This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Timezone won't display local Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Timezone won Watch "Timezone won New topic
Author

Timezone won't display local

randy reed
Greenhorn

Joined: Dec 13, 2012
Posts: 1
Hi All,

So this should be simple, but I can't figure it out. No matter what I do, my local timezone displays as GMT-5:00.
I need it to display as EDT/EST because I want to set a milli date and then query whether its in daylight savings time or not
but setting the timezone object with tz.setTimeZone("America/New_York") displays GMT-5:00
when I display a date in september. I've tried setting the user.timezone property in sys.
I've tried setting in SimpleDateFormat as well. My Code looks like this:


My output returns:
12/14/2012 05:47 GMT
Timezone =GMT-05:00
Date = Fri Dec 14 05:47:34 GMT 2012
Calendar = java.util.GregorianCalendar[time=1355464054992,areFieldsSet=true,areAllFieldsSet=true,lenient=true,
zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2012,MONTH=11,WEEK_OF_YEAR=50,
WEEK_OF_MONTH=3,DAY_OF_MONTH=14,DAY_OF_YEAR=349,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2,
AM_PM=0,HOUR=5,HOUR_OF_DAY=5,MINUTE=47,SECOND=34,MILLISECOND=992,ZONE_OFFSET=0,DST_OFFSET=0]

I'm sure I don't understand something but I'm stuck.
btw: my actual timezone is EST which is equivalent to GMT-05:00, but I don't understand why it displays as a
custom timezone rather than just EST. And why the calendar object and Date object both display GMT.

Thanks in advance
Randy
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Welcome to the Ranch

Have a look at the TimeZone documentation. It doesn’t say anything about summer time and winter time or daylight saving time and night-time extending time. The time zone remains constant whether it is summer or winter. I know there is a database somewhere in the JRE of summer and winter times worldwide, because I keep getting messages saying it has to be updated. Remember Moscow, which ought to be several feet deep in snow now, and Cape Town, where it is almost midsummer, are in the same time zone, so summer time is not linked directly to time zones.
I don’t know much more about time zone objects, but you appear to have a couple of fields called DST_SOMETHING. You could try reading the TimeZone#toString documentation, and the documentation for this class.
I also looked at the Calendar class and the Date class and this is the only thing I found.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
That toString() method documentation was less helpful that I had thought!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Timezone won't display local
 
Similar Threads
Converting from GMT to Local Timezone using two seperate fields (date & time).
Change Timezone from GMT to EST, the best way to accomplish?
Need Help on Time conversion.
changing timzone using calender api
Timestamp advanced 4 hours