Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Timezone problem

Thread view: 
ahjiang@gmail.com - 11 May 2006 03:56 GMT
Hi all,

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss z");
java.util.Date date = new java.util.Date();
System.out.println(dateFormat.format(date));

I having this piece of code and the output is

2006-05-11 02:54:00 GMT

My location is GMT +8. So i would need to add in another 8 hrs to the
time.

How can i do it such that the piece of code would always offset the
time correctly?

Appreciate any help
Chris Smith - 11 May 2006 05:04 GMT
>  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd
> HH:mm:ss z");
[quoted text clipped - 10 lines]
> How can i do it such that the piece of code would always offset the
> time correctly?

SimpleDateFormat extends DateFormat, so it inherits a method called
setTimeZone.  That does what you want, if I understand you well.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Steve W. Jackson - 11 May 2006 17:04 GMT
> >  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd
> > HH:mm:ss z");
[quoted text clipped - 13 lines]
> SimpleDateFormat extends DateFormat, so it inherits a method called
> setTimeZone.  That does what you want, if I understand you well.

While calling setTimeZone will provide the result, it might be better to
use a Calendar, or perhaps a GregorianCalendar.  This should
automatically contain a date/time with time zone info included.  
SimpleDateFormat inherits the setCalendar method, too, and calling that
will give it the information included in a new Date object but include
TZ data as well.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.