File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes CurrentTimeMillis return problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "CurrentTimeMillis return problem" Watch "CurrentTimeMillis return problem" New topic
Author

CurrentTimeMillis return problem

Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Hello Experts,

1. I went on http://docs.oracle.com/javase/7/docs/api/ to get a glimpse on the CurrentTimeMillis() method. But, the answer is so ambiguous. CurrentTimeMillis returns the current time in milliseconds or the difference between current time and midnight 1 Jan 1970 ?

public static long currentTimeMillis()

Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).

Returns:
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
See Also:
Date


2. On my machine every time I run this code, 1 is displayed, each run being made at a different time.

Any ideas ?

Thank you very much for all your help, patience and time

kind regards,
radu




NEW Edit :


Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3366
    
    9
currentTimeMillis() returns the current time. The current time is given in milliseconds since Jan 1st 1970. There's nothing ambiguous about it. You can only have a notion of time if you have a moment you start counting from.

The code you posted won't work. The method name is "currentTimeMillis" and the class name is "System". Note capitalization.
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Stephan van Hulst wrote:currentTimeMillis() returns the current time. The current time is given in milliseconds since Jan 1st 1970. There's nothing ambiguous about it. You can only have a notion of time if you have a moment you start counting from.

The code you posted won't work. The method name is "currentTimeMillis" and the class name is "System". Note capitalization.


Thank you so much for your answer Shephan ! However :

1. I edited my initial post, and updated it with your recommendations. But I still get the same output as before :

dir_path>java DisplayCurrentTime
Current time is 13:19:39GMT
1

It seems to me that the nr of miliseconds is not shown. And this number represents how any miliseconds are in 14 hours 19 minutes and 39 seconds ?

thank you very much for your help,

kind regards,
radu
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Stephan van Hulst wrote:currentTimeMillis() returns the current time. The current time is given in milliseconds since Jan 1st 1970. There's nothing ambiguous about it. You can only have a notion of time if you have a moment you start counting from.


I don't understand if this method converts the the current time in milliseconds or returns the number of milliseconds since 1 Jan 1970 ?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7029
    
  16

Marius Constantin wrote:
Stephan van Hulst wrote:currentTimeMillis() returns the current time. The current time is given in milliseconds since Jan 1st 1970. There's nothing ambiguous about it. You can only have a notion of time if you have a moment you start counting from.

I don't understand if this method converts the the current time in milliseconds or returns the number of milliseconds since 1 Jan 1970 ?

I don't understand what your confusion is: both Stephan's answer and the documentation are absolutely clear.

What do you think "current time" means? The time of day (ie, the time on a clock)? If so, then you are wrong, because then it would be different depending on where you are in the world, and Java needs to work the same for everybody.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3165
    
  10
Marius Constantin wrote:I still get the same output as before :

dir_path>java DisplayCurrentTime
Current time is 13:19:39GMT
1

The code you posted will not give that output. There is nothing that prints Current time is 13:19:39GMT. So why don't you show us the exact code you are using.


Joanne
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Joanne Neal wrote:
Marius Constantin wrote:I still get the same output as before :

dir_path>java DisplayCurrentTime
Current time is 13:19:39GMT
1

The code you posted will not give that output. There is nothing that prints Current time is 13:19:39GMT. So why don't you show us the exact code you are using.


thank you so much Joanne. You're right. This output was coming from another code. I have just noticed.
Marius Constantin
Ranch Hand

Joined: Nov 23, 2011
Posts: 62

Winston Gutkowski wrote:
Marius Constantin wrote:
Stephan van Hulst wrote:currentTimeMillis() returns the current time. The current time is given in milliseconds since Jan 1st 1970. There's nothing ambiguous about it. You can only have a notion of time if you have a moment you start counting from.

I don't understand if this method converts the the current time in milliseconds or returns the number of milliseconds since 1 Jan 1970 ?

I don't understand what your confusion is: both Stephan's answer and the documentation are absolutely clear.

What do you think "current time" means? The time of day (ie, the time on a clock)? If so, then you are wrong, because then it would be different depending on where you are in the world, and Java needs to work the same for everybody.

Winston


thank you winston. The name coincidence and the output coming out from another code ran, got me all mixed up. thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CurrentTimeMillis return problem
 
Similar Threads
getWhen() of ActionEvent
View Of Native Functions of JAVA
Current Timestamp in microseconds
System.currentTimeMillis() is not UTC in Milliseconds since 1.1.1970 ! Official JavaDoc wrong?
Geting Current Time in Seconds?