Formula of currentTimeMillis() in java?

To my knowledge, System.currentTimeMillis()/1000 can show the current time in seconds since

1970-1-1 00:00:00 (YY-MM-DD HH:mm:ss)

For example

2013-10-12 21:30:00 (YY-MM-DD HH:mm:ss)

= 13815846XX (not sure whats X for)

I was wondering how to calculate it. Thanks a lot!!!!

Jon Skeet
people
quotationmark

System.currentTimeMillis() just returns the number of milliseconds since the Unix epoch (January 1st 1970, midnight UTC), as a long.

Converting that value into a string is normally the job of something like SimpleDateFormat, via Calendar and Date. Alternatively, look at Joda Time for a nicer date/time API.

If you want to start with a date and get the number of milliseconds since the Unix epoch, you'd use Calendar, set the appropriate fields and then use Calendar.getTimeInMillis(). (Or again, use Joda Time.) Be careful about time zone interactions.

You can use Epoch Converter to check your computations.

A value such as 1381584600 is most likely to be a Unix timestamp, which is the number of seconds (not milliseconds) since the Unix epoch - hence the division by 1000 that you mention.

If this doesn't tell you what you need, please ask a more precise question.

people

See more on this question at Stackoverflow