aspose file tools*
The moose likes Java in General and the fly likes timestamp in jdk1.4 and jdk1.7 (Gives two different result) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "timestamp in jdk1.4 and jdk1.7 (Gives two different result)" Watch "timestamp in jdk1.4 and jdk1.7 (Gives two different result)" New topic
Author

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

thilsen kumar
Greenhorn

Joined: Jul 10, 2007
Posts: 13
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

Joined: Oct 13, 2005
Posts: 39380
    
  28
Please read the important administrative private message I just sent you.
thilsen kumar
Greenhorn

Joined: Jul 10, 2007
Posts: 13
Campbell Ritchie wrote:Please read the important administrative private message I just sent you.


ok
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39380
    
  28
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

Joined: Jun 20, 2008
Posts: 7
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

Joined: Jul 10, 2007
Posts: 13
Thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39380
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: timestamp in jdk1.4 and jdk1.7 (Gives two different result)