• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

java.util.date time is different than the system time  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

my log files show different timezone, where as my system time zone is different.
java.util.date itself shows diffrent time. Please suggest.
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where and how do you print the time ?
 
sumitha sudhakar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I am using windows 7. my system time is 11:44 AM, but if i try to dispaly the time using normal java code;
Date dt = new Date();
System.out.println("date is"+dt);

i am getting different time date isTue Nov 16 06:14:38 GMT 2010
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sumitha sudhakar wrote:hi,

I am using windows 7. my system time is 11:44 AM, but if i try to dispaly the time using normal java code;
Date dt = new Date();
System.out.println("date is"+dt);

i am getting different time date isTue Nov 16 06:14:38 GMT 2010



You can use the SimpleDateFormat to specify the Locale and the format you want the date in.

Update: You can even try Calendar class.
 
sumitha sudhakar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is by default it has to display the date in system date and time zone only not the GMT timezone.
Correct me if i am wrong.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that if it does not recognize your timezone, GMT will be used by default. If you want to specify a specific format, you have to use a DateFormat, like SimpleDateFormat.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!