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_t ime) + "|" +
component_name + "|" + log_message + "\n";
thanks.
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'
//populate log_string with formatted trace message
log_string = formatter.format(current_t
component_name + "|" + log_message + "\n";
thanks.
ASKER
Hello,
I don't understand.
I did System.out.println( TimeZone.getDefault().getI D() );
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 ?
I don't understand.
I did System.out.println( TimeZone.getDefault().getI
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks.
formatter.setTimeZone(new SimpleTimeZone("EST");
to switch to the Eastern Strandard Time. Look at TimeZone class for other examples of use.