Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java Micro Edition and the fly likes currentTimeMillis() and Date.getTime() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "currentTimeMillis() and Date.getTime()" Watch "currentTimeMillis() and Date.getTime()" New topic

currentTimeMillis() and Date.getTime()

Shrihan De Mel

Joined: Jan 15, 2007
Posts: 3

is there a difference between the format returned by System.currentTimeMillis() and Date.getTime()

to further clarify, can we directly compare two variables that possess values from each one of the above methods, as if both of them are assigned from one of the above ways

your help if much appreciated

Paul Clapham

Joined: Oct 14, 2005
Posts: 19870

They both return long values, so there is no difference in the format. You can directly compare two long values, yes.

You may have meant to ask if you should expect those two long values to be the same, although you really only asked about the format and not about the content. Both contain a number of milliseconds since a certain point of time, so if you evaluate the two expressions at the same instant, you should expect to get the same value in both cases.
I agree. Here's the link:
subject: currentTimeMillis() and Date.getTime()
It's not a secret anymore!