• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Puzzling Parsing of Dates

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello

I am new to Java and developing First Java Application. Please refer following code and the output.

System is Kubuntu 9.10 JDK 1.6 Repository Install, STS 2.3.2.

public static void main(String[] args) {

// Mon Jan 01 05:53:20 IST 1900
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
TimeZone tz = TimeZone.getDefault();

System.out.println("RawOffset = " + tz.getRawOffset() + " useDaylightTime = " + tz.useDaylightTime());
try {
Date dt1 = fmt.parse("Mon Jan 01 05:30:00 IST 1900");
Date dt2 = fmt.parse("Mon Jan 01 05:29:59 IST 1900");

System.out.println("date = " + dt1 + " offset = " + tz.getOffset(dt1.getTime()) + " getTime = "
+ dt1.getTime());
System.out.println("date = " + dt2 + " offset = " + tz.getOffset(dt2.getTime()) + " getTime = "
+ dt2.getTime());
}
catch (ParseException e) {
e.printStackTrace();
}
}
}

RawOffset = 19800000 useDaylightTime = false
date = Mon Jan 01 05:53:20 IST 1900 offset = 21200000 getTime = -2208988800000
date = Mon Jan 01 05:29:59 IST 1900 offset = 19800000 getTime = -2208988801000

I am confused why diff of 1 sec at threshold of timezone offset of 05:30 is converting date to 05:53:20 when
the raw date millis have changed correctly by 1 sec. You can see that offset has also shifted by 23:20 so
addition of 23:20 can be understood but why should it happen ? How can I get correct time of 05:30 if its
default behavior.

Thanks and Best Regards.

Raja
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi raja, welcome to JavaRanch! Please UseCodeTags, as it makes your code easier to read and fix.

It seems like it's not parsing your first Date correctly. What happens when you manually pull the minute value out of the Date?

 
raja patil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael Angstadt,

Here is Out put

regards

Raja
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to run your code and this is my output. I dont see anything wierd here:
 
raja patil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sai prashanth wrote:I tried to run your code and this is my output. I dont see anything wierd here:



Thanks Sai prashanth have you tried with IST (india not Irish i.e. GMT+0530) rather than CST timezone ?
Please noticed offset values 19800000 and 21200000 that is causing problem I believe.
another thing is that from 05:29:59 to 05:30:00 there is jump of 00:23:20 and after that
it increments linearly with input value.

Thanks and regards

Raja
 
raja patil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

I just found this http://72.5.124.102/thread.jspa?messageID=10811150 which explains things about IST timezone
is really java gets confused with 3 letter timezone ? If yes then what shout I use so that java wont get confused.

Thanks and regards

Raja
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html

See specifically the section on three-letter timezone names.
 
raja patil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all who contributed to this thread,

It Seems that there is No problem with IST. The history of IST (Indian Standard Time) Like that only.
Before 1900 there was no definition of IST.
initially IST was using Madras (Chennai) Time then Kolkata time then after Independence in 1947
its using Ujain i.e. Meridian Passing through almost centre of the state so there are three different
offsets the listing below clearly indicates that. During analysis of this issue I learnt that timezones
are fixed by Politicians and not by scientists thats why there are many such issues to be dealt with
by programmers by simply setting time zone to GMT+0530 all the date time issues get vanished.



with TimeZone "GMT+0530"



Thanks and best regards

Raja
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic