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 / July 2006

Tip: Looking for answers? Try searching our database.

Calendar get method

Thread view: 
terloon - 12 Jul 2006 17:07 GMT
Hello,

I know there are a lot of issues with the Calendar class in Java (from
my searches anyway), but I can't seem to find one for my simple
question. When using the get methods of the calendar class, which
timezone is it using? I've changed the default time zone using
TimeZone.setDefault and have set the timezone of the Calendar object
itself, but it seems to keep returning values for a GMT timezone. Where
can I set it so the get methods of the Calendar class return the
correct values for a timezone I specify?

T.Ramos
Danno - 12 Jul 2006 17:38 GMT
> Hello,
>
[quoted text clipped - 8 lines]
>
> T.Ramos

It's default uses the time zone of your machine....Try out some of this
code, and maybe it will help you with what you are looking for...

       Calendar cal = Calendar.getInstance();
       System.out.println(cal.getTimeZone());

       //List of Ids, you'll need these to set the timezone.
       for (String id : TimeZone.getAvailableIDs()) {
           System.out.println(id);
       }

       TimeZone parisZone = TimeZone.getTimeZone("Europe/Paris");

       DateFormat def =
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
Locale.FRANCE);
       def.setTimeZone(parisZone);

       Calendar cal2 = Calendar.getInstance(parisZone);
       System.out.println(cal2.get(Calendar.HOUR));
       System.out.println(def.format(cal2.getTime()));
       System.out.println(cal2.getTimeZone());
       System.out.println(cal2.getTime()); //Careful toString() of
java.util.Date does things different
terloon - 12 Jul 2006 18:46 GMT
> It's default uses the time zone of your machine....Try out some of this
> code, and maybe it will help you with what you are looking for...

So does this mean that it doesn't matter how I set the TimeZone via
TimeZone.setDefault() or the setTimeZone method of the
GregorianCalendar object, it will always use the TimeZone of my
machine?
Danno - 12 Jul 2006 19:08 GMT
> > It's default uses the time zone of your machine....Try out some of this
> > code, and maybe it will help you with what you are looking for...
[quoted text clipped - 3 lines]
> GregorianCalendar object, it will always use the TimeZone of my
> machine?

Check out the code, you can set the timezone of a Calendar object and
it works.
terloon - 12 Jul 2006 19:20 GMT
> > > It's default uses the time zone of your machine....Try out some of this
> > > code, and maybe it will help you with what you are looking for...
[quoted text clipped - 6 lines]
> Check out the code, you can set the timezone of a Calendar object and
> it works.

Oh bother, it does work. I had a setTimeZone hidden away setting it
back to GMT unbeknownst to me. Chalk this one up to carelessness.
Danno - 12 Jul 2006 20:03 GMT
> > > > It's default uses the time zone of your machine....Try out some of this
> > > > code, and maybe it will help you with what you are looking for...
[quoted text clipped - 9 lines]
> Oh bother, it does work. I had a setTimeZone hidden away setting it
> back to GMT unbeknownst to me. Chalk this one up to carelessness.

;) Happens to all of us.


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.