Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timestamp advanced 4 hours

 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a timezone problem.
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check which time zone you are using
See whether that helps at all.
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
America/New_York

wich is the correct time for Boston, but when I run my project in Netbeans, I got 4 hours ahead.
 
Kamal Ahmed
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you import Timestamp from?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15436
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic