Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

timestamp in jdk1.4 and jdk1.7 (Gives two different result)

 
thilsen kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want clarify one thing.
I installed j2sdk1.4.2_03 and jdk1.7 in my system.
when i run the following program it gives two different result in two version of java
my system timezone setting is -08:00 (Pacific US & Canada )

import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;

class DB {
public static void main (String args []) throws SQLException
{
try {
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss Z");
Timestamp today = new Timestamp(df.parse("20081027023050 -0800").getTime());
System.out.println("Today = " + df.format(today));
}catch (ParseException e)
{ e.printStackTrace(); }
}
}



when i run this with jdk1.4... it gives 20081027023050 -0800
when i run this with jdk1.7 it gives 20081027033050 -0700
Can anybody clarify this?

Thanks & Regards,
thilsen
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the important administrative private message I just sent you.
 
thilsen kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Please read the important administrative private message I just sent you.


ok
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

Welcome to JavaRanch

It is worthwhile checking whether there have been any changes to the rules about daylight saving time in the USA between 2001 when J2SE1.4 came out and 2006 when Java6 came out. That might explain the difference. Apart from that, I am afraid, don't know.
By the way, what's jdk1.7? Java7 hasn't been issued yet. Is it a version of gcj? I seem to remember my Fedora compiler is capable of saying it's 1.7.
 
Amit Singla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you see, both the times are same the only difference is the default value of timezone.

Please see this... http://java.sun.com/javase/timezones/.. java guys talk about this thing. I think 2007 onwards there are standard days when Daylight saving will be done so java compute the time zone (with daylight saving) based on these rules. In your programme, if yoy change the month to 12 (from 10)... you will start seeing time in -8:00 hrs.
 
thilsen kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic