paries
asked on
having trouble with time zones and daylight savings
So i have this time in my DB
1300550400000
from what i read the display should no if to display daylight or not
when i run this code::
SmsEvents.getStart() returns 1300550400000
TimeZone pTz = TimeZone.getTimeZone( "PST" );
DateFormat pdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
pdf.setTimeZone( pTz );
Calendar dayp = Calendar.getInstance();
dayp.setTimeZone( pTz );
dayp.setTime( new Date((long)SmsEvents.getSt art()) );
System.out.println( pdf.format( dayp.getTime() ) );
TimeZone mTz = TimeZone.getTimeZone( "MST" );
DateFormat mdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
mdf.setTimeZone( mTz );
Calendar daym = Calendar.getInstance();
daym.setTimeZone( mTz );
daym.setTime( new Date((long)SmsEvents.getSt art()) );
System.out.println( mdf.format( daym.getTime() ) );
TimeZone cTz = TimeZone.getTimeZone( "CST" );
DateFormat cdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
cdf.setTimeZone( cTz );
Calendar dayc = Calendar.getInstance();
dayc.setTimeZone( cTz );
dayc.setTime( new Date((long)SmsEvents.getSt art()) );
System.out.println( cdf.format( dayc.getTime() ) );
i get the following results::
March 19, 2011 9:30:00 AM PDT
March 19, 2011 9:30:00 AM MST
March 19, 2011 11:30:00 AM CDT
why is mountain doing this. Am i doing something wrong?
I am confused
1300550400000
from what i read the display should no if to display daylight or not
when i run this code::
SmsEvents.getStart() returns 1300550400000
TimeZone pTz = TimeZone.getTimeZone( "PST" );
DateFormat pdf = DateFormat.getDateTimeInst
pdf.setTimeZone( pTz );
Calendar dayp = Calendar.getInstance();
dayp.setTimeZone( pTz );
dayp.setTime( new Date((long)SmsEvents.getSt
System.out.println( pdf.format( dayp.getTime() ) );
TimeZone mTz = TimeZone.getTimeZone( "MST" );
DateFormat mdf = DateFormat.getDateTimeInst
mdf.setTimeZone( mTz );
Calendar daym = Calendar.getInstance();
daym.setTimeZone( mTz );
daym.setTime( new Date((long)SmsEvents.getSt
System.out.println( mdf.format( daym.getTime() ) );
TimeZone cTz = TimeZone.getTimeZone( "CST" );
DateFormat cdf = DateFormat.getDateTimeInst
cdf.setTimeZone( cTz );
Calendar dayc = Calendar.getInstance();
dayc.setTimeZone( cTz );
dayc.setTime( new Date((long)SmsEvents.getSt
System.out.println( cdf.format( dayc.getTime() ) );
i get the following results::
March 19, 2011 9:30:00 AM PDT
March 19, 2011 9:30:00 AM MST
March 19, 2011 11:30:00 AM CDT
why is mountain doing this. Am i doing something wrong?
I am confused
ASKER
so my question is why is it
March 19, 2011 9:30:00 AM MST
should it have not been MDT??
March 19, 2011 9:30:00 AM MST
should it have not been MDT??
I got different output:
March 19, 2011 8:00:00 AM PST
March 19, 2011 9:00:00 AM MST
March 19, 2011 10:00:00 AM CST
I just modified your code a little bit (replacing SMSEvent):
TimeZone pTz = TimeZone.getTimeZone( "PST" );
DateFormat pdf = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG );
pdf.setTimeZone( pTz );
Calendar dayp = Calendar.getInstance();
dayp.setTimeZone( pTz );
dayp.setTime( new Date((long)1300550400000L));
System.out.println( pdf.format( dayp.getTime() ) );
TimeZone mTz = TimeZone.getTimeZone( "MST" );
DateFormat mdf = DateFormat.getDateTimeInstance( DateFormat.LONG,DateFormat.LONG );
mdf.setTimeZone( mTz );
Calendar daym = Calendar.getInstance();
daym.setTimeZone( mTz );
daym.setTime( new Date((long)1300550400000L) );
System.out.println( mdf.format( daym.getTime() ) );
TimeZone cTz = TimeZone.getTimeZone( "CST" );
DateFormat cdf = DateFormat.getDateTimeInstance( DateFormat.LONG,DateFormat.LONG );
cdf.setTimeZone( cTz );
Calendar dayc = Calendar.getInstance();
dayc.setTimeZone( cTz );
dayc.setTime( new Date((long)1300550400000L) );
System.out.println( cdf.format( dayc.getTime() ) );
When I changed all thre of them to
PDT, MDT nd CDT I got everything in GMT, like that:
Interesting, indeed
PDT, MDT nd CDT I got everything in GMT, like that:
March 19, 2011 4:00:00 PM GMT
March 19, 2011 4:00:00 PM GMT
March 19, 2011 4:00:00 PM GMT
Interesting, indeed
ASKER
i am running 1.5 i bet you you are running 1.6
I was just posting that I have Java 1.5 (1.5.0_01)
(even more surprising).
Did you change to that same long number (just to have the codes identical).
(even more surprising).
Did you change to that same long number (just to have the codes identical).
I'm in Pacific zone, so my local time is 11:06 I guess it is PDT
ASKER
so i am using jdk1.5.0_15
wow this is so confusing....
I am at a loss
thats for you help.
wow this is so confusing....
I am at a loss
thats for you help.
It looks like my java does not understand PDT, CDT, MDT;
when I put "ABC" instaed - I also get GMT time in the result
when I put "ABC" instaed - I also get GMT time in the result
ASKER
yeah that is the same with me.
but if i put in CST it realized i am in daylight savings and shows CDT
but if i put in CST it realized i am in daylight savings and shows CDT
ASKER
wow, so i took this very simple jsp and moved to a 1.6.0_20 box
go the same results
March 19, 2011 11:25:22 AM PDT
March 19, 2011 11:25:22 AM MST
March 19, 2011 1:25:22 PM CDT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page import="java.text.SimpleDa teFormat" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.DecimalF ormat" %>
<%@ page import="java.text.DateForm at" %>
<%@ page contentType="text/html;cha rset=UTF-8 " language="java" %>
<%
Date now2 = new Date();
TimeZone pTz = TimeZone.getTimeZone( "PST" );
DateFormat pdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
pdf.setTimeZone( pTz );
Calendar dayp = Calendar.getInstance();
dayp.setTimeZone( pTz );
dayp.setTime( now2 ) ;
System.out.println( pdf.format( dayp.getTime() ) );
TimeZone mTz = TimeZone.getTimeZone( "MST" );
DateFormat mdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
mdf.setTimeZone( mTz );
Calendar daym = Calendar.getInstance();
daym.setTimeZone( mTz );
daym.setTime( now2 );
System.out.println( mdf.format( daym.getTime() ) );
TimeZone cTz = TimeZone.getTimeZone( "CST" );
DateFormat cdf = DateFormat.getDateTimeInst ance( DateFormat.LONG,DateFormat .LONG );
cdf.setTimeZone( cTz );
Calendar dayc = Calendar.getInstance();
dayc.setTimeZone( cTz );
dayc.setTime( now2 );
System.out.println( cdf.format( dayc.getTime() ) );
%>
go the same results
March 19, 2011 11:25:22 AM PDT
March 19, 2011 11:25:22 AM MST
March 19, 2011 1:25:22 PM CDT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page import="java.text.SimpleDa
<%@ page import="java.util.*" %>
<%@ page import="java.text.DecimalF
<%@ page import="java.text.DateForm
<%@ page contentType="text/html;cha
<%
Date now2 = new Date();
TimeZone pTz = TimeZone.getTimeZone( "PST" );
DateFormat pdf = DateFormat.getDateTimeInst
pdf.setTimeZone( pTz );
Calendar dayp = Calendar.getInstance();
dayp.setTimeZone( pTz );
dayp.setTime( now2 ) ;
System.out.println( pdf.format( dayp.getTime() ) );
TimeZone mTz = TimeZone.getTimeZone( "MST" );
DateFormat mdf = DateFormat.getDateTimeInst
mdf.setTimeZone( mTz );
Calendar daym = Calendar.getInstance();
daym.setTimeZone( mTz );
daym.setTime( now2 );
System.out.println( mdf.format( daym.getTime() ) );
TimeZone cTz = TimeZone.getTimeZone( "CST" );
DateFormat cdf = DateFormat.getDateTimeInst
cdf.setTimeZone( cTz );
Calendar dayc = Calendar.getInstance();
dayc.setTimeZone( cTz );
dayc.setTime( now2 );
System.out.println( cdf.format( dayc.getTime() ) );
%>
I'll be in the office this afternoon; I have sveral java's there including 1.6 - I'll give it a try
All that looks really strange
ASKER
after some googling seems to be a common problem
if i do TimeZone mTz = TimeZone.getTimeZone( "America/Denver" );
it displays correctly
I think i am going to go that route
thanks for all your help
if i do TimeZone mTz = TimeZone.getTimeZone( "America/Denver" );
it displays correctly
I think i am going to go that route
thanks for all your help
And thanks for this interesting news also
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If all stuff which is deprecated in Java would stop working today - we'll have a disaster much worse than any Japanese tsunami.
Well tzs are a little different than stuff like deprecated methods:
a. they are a moving target for Java
b. they're already either buggy or borderline buggy
For those reasons, it's worth running the tzupdater tool - it won't do you any harm and might do some good
a. they are a moving target for Java
b. they're already either buggy or borderline buggy
For those reasons, it's worth running the tzupdater tool - it won't do you any harm and might do some good
seems logical to me, I guess MST will give the same number as PDT
CDT is two hours difference with PDT
and I guess MDT will be one hour difference with PDT.
Isn't that what you'll expect?