• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get System Timezone?

 
Diksha Neel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Diksha, I guess that all you need is something like



Regards
 
Diksha Neel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maurizio !

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

Thanks,
Diksha
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Binod Suman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you just want print the zone...then you might want to use

prints just BST
 
Harsha Kasturi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TimeZone timeZone = Calendar.getInstance().getTimeZone();
System.out.println(timeZone.getDisplayName(false, TimeZone.SHORT));
This has worked for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic