aspose file tools*
The moose likes Java in General and the fly likes How to get System Timezone? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get System Timezone?" Watch "How to get System Timezone?" New topic
Author

How to get System Timezone?

Diksha Neel
Greenhorn

Joined: May 06, 2008
Posts: 5
My system is configured to be in BST Timezone. But
spZone = java.util.TimeZone.getDefault(); gives me "GMT".

What is the command to get the system timezone i.e. BST?

Thanks in advance,
Diksha
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Originally posted by Diksha Neel:
My system is configured to be in BST Timezone. But
spZone = java.util.TimeZone.getDefault(); gives me "GMT".

What is the command to get the system timezone i.e. BST?

Thanks in advance,
Diksha


On my Ubuntu804 system using JDK1.6.0_07, BST is not "British Standard Time" but "Bangladesh Time" .

Please run


Also, when I run
I get
Greenwich Mean Time
GB


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Originally posted by James Sabre:

Also, when I run
I get
Greenwich Mean Time
GB


It is interesting that when I run that code on Windows XP SP3 using 1.6.0_07 I get

Greenwich Mean Time
Europe/London
Diksha Neel
Greenhorn

Joined: May 06, 2008
Posts: 5
Hi James! Thanks for the reply but what I am looking for is printing the SYSTEM Timezone...whatever be it -BST/EST/IST etc.

So if my System in configured to be in say XYZ timezone, I wish my Java code to be able to print this XYZ timezone.

What is the command for this? I am using Java 1.4.2.

Thanks,
Diksha
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Originally posted by Diksha Neel:
Hi James! Thanks for the reply but what I am looking for is printing the SYSTEM Timezone...whatever be it -BST/EST/IST etc.

So if my System in configured to be in say XYZ timezone, I wish my Java code to be able to print this XYZ timezone.

What is the command for this? I am using Java 1.4.2.

Thanks,
Diksha


Sorry but I don't think I can help. The only way I know of accessing the timezone is though the TimeZone class and if this does not give you the timezone ID in the format you want then nothing obvious and portable springs to mind.
Maurizio Nagni
Ranch Hand

Joined: May 29, 2004
Posts: 75
Diksha, I guess that all you need is something like



Regards
Diksha Neel
Greenhorn

Joined: May 06, 2008
Posts: 5
Hi Maurizio !

This also returns GMT...and not the actual system timezone.

Thanks,
Diksha
Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

Diksha, i am sorry if i understood it wrongly i tried the code given as
----------------
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println(tz.getDisplayName());// (i.e. Moscow Standard Time)
System.out.println(tz.getID());
-----------------
and for me the output was
---------------------
India Standard Time
Asia/Calcutta
---------------------
then i went back and changed the time zone to Singapor and got the followng output
----------------------
Singapore Time
Asia/Singapore

----------------------
it is taking the time zone dynamically and shownig it so where is your problem?

one more thing i added following line of code

System.out.println(tz.getTimeZone(tz.getID()));//will this help ?


[ October 24, 2008: Message edited by: Tanu Gulati ]
[ October 24, 2008: Message edited by: Tanu Gulati ]

thanks
Tanu Gulati
Binod Suman
Greenhorn

Joined: May 07, 2008
Posts: 17
I have also post similar type of Java example to How to get other TimeZone time by JAVA.

http://binodjava.blogspot.com/2009/05/how-to-get-other-timezone-time-by-java.html

Thanks,

Binod Suman

http://binodsuman.blogspot.com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
By the way: It's not "British Standard Time" which we suffered from about 1969-1971. BST means British Summer Time. What in the States they call daylight saving time.
jittu goud
Ranch Hand

Joined: Mar 30, 2007
Posts: 46
i had issues with this previously....

when i run the


its prints GMT for me...

output
Greenwich Mean Time
Europe/London
09:50:07


but if i use simpledateformat...it prints correct ,,,



its prints the right time and time zone for me ...


output---Thu May 14 21:50:07 BST 2009
jittu goud
Ranch Hand

Joined: Mar 30, 2007
Posts: 46
if you just want print the zone...then you might want to use

prints just BST
Harsha Kasturi
Greenhorn

Joined: Jun 24, 2013
Posts: 1
jittu goud wrote:i had issues with this previously....

when i run the


its prints GMT for me...

output
Greenwich Mean Time
Europe/London
09:50:07


but if i use simpledateformat...it prints correct ,,,



its prints the right time and time zone for me ...


output---Thu May 14 21:50:07 BST 2009



Sorry for late reply.................

In order to get the short timezone like "BST" you could use the code below

diksha singh neel
Greenhorn

Joined: Jul 28, 2013
Posts: 10
TimeZone timeZone = Calendar.getInstance().getTimeZone();
System.out.println(timeZone.getDisplayName(false, TimeZone.SHORT));
This has worked for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get System Timezone?