File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Timestamp advanced 4 hours Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Timestamp advanced 4 hours " Watch "Timestamp advanced 4 hours " New topic

Timestamp advanced 4 hours

majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Timestamp ts = new Timestamp(new Date().getTime());

I am displaying the Timestamp , but instead of showing :

Last Update: 2007-10-09 13:29:32.0

it shows
Last Update: 2007-10-09 17:29:32.0

can you please help me.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19718

Looks like a timezone problem.

How To Ask Questions How To Answer Questions
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
I am living here in Est Cost, but still get the UTC time, 4 hours ahead.
how to set the time to be my local time.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 39393
Check which time zone you are using
See whether that helps at all.
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164

wich is the correct time for Boston, but when I run my project in Netbeans, I got 4 hours ahead.
Kamal Ahmed
Ranch Hand

Joined: Feb 15, 2005
Posts: 91
Where did you import Timestamp from?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14268

Originally posted by majid nakit:
I am displaying the Timestamp , ...

How are you displaying the timestamp? You can use a DateFormat object to format a date any way you like, and set the timezone on the DateFormat object to show it in a specific timezone. For example:

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Timestamp advanced 4 hours