wood burning stoves 2.0*
The moose likes Java in General and the fly likes java.util.date time is  different than the system time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.util.date time is  different than the system time" Watch "java.util.date time is  different than the system time" New topic
Author

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

sumitha sudhakar
Greenhorn

Joined: Aug 09, 2010
Posts: 21
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.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Where and how do you print the time ?


[My Blog]
All roads lead to JavaRanch
sumitha sudhakar
Greenhorn

Joined: Aug 09, 2010
Posts: 21
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
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

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

Joined: Aug 09, 2010
Posts: 21
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
 
wood burning stoves
 
subject: java.util.date time is different than the system time
 
Similar Threads
System.out.println in jsp
sql date or util date
How do I calculate the no.of.days. between two timestamps?
Date default in SQL Server
not all variables bound Error