• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please read the important administrative private message I just sent you.



ok
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic