tags:

views:

76

answers:

2

I need to store the current time as long integer into a database table, there are maybe better ways to store date/time in database, but here long integer is the requirement.

In PHP, I can get the current time in integer with time(), in Java, is there any function or simple code that do the same trick?

Thank you

+7  A: 

You can do System.currentTimeMillis() which returns a long.

From the JavaDoc:

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)

Amir Afghani
And parse with Timestamp
Byron Whitlock
A: 

Sounds like java.util.Date.getTime() is what you're looking for. The PHP time() function is in seconds though, and the Java function is in milliseconds so you'll want to do a conversion depending on the unit you need.

Greg Shackles