Link to home
Start Free TrialLog in
Avatar of kkandasa
kkandasa

asked on

Date/Time question

Hello,
 I have been using the following code to print out the
date & time as part of a trace to a file.
The time being printed in Pacific Standard Time. Even
though the host computer time is Eastern Standard time.
Why is this ?

            //format date & time
            Date current_time = new Date();

            SimpleDateFormat formatter = new SimpleDateFormat("dd'/'MM'/'yyyy HH':'mm':'ss'.'SSS");

            //populate log_string with formatted trace message
            log_string = formatter.format(current_time) + "|" +
                        component_name +       "|" + log_message + "\n";

thanks.
Avatar of msmolyak
msmolyak

Do

formatter.setTimeZone(new SimpleTimeZone("EST");

to switch to the Eastern Strandard Time. Look at TimeZone class for other examples of use.
Avatar of kkandasa

ASKER

Hello,

I don't understand.
I did System.out.println( TimeZone.getDefault().getID() );
and my system is using EST. Why is SimpleDateFormat class
does not look at the default timezone ?
How do I set the default timezone and SimpleDateFormat class
looks at ?

Why SimpleDateFormat is not using a default time zone I don't know (you may look in the source code to see what they do). Use the method stated in the answer to change the time zone of the data formatter.
ASKER CERTIFIED SOLUTION
Avatar of fontaine
fontaine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks.