• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where and how do you print the time ?
 
sumitha sudhakar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic