Reputation: 95
I have a SQL table which contains a column called 'joindate'. I need to enter a value in it, and it has to be an integer. An example of a value in this column is 1374966278, which is 07-27-2013.
How would I generate such a number using Java?
Upvotes: 1
Views: 67
Reputation: 425418
That number is the number of seconds since 1970-01-01.
Use current epoch milliseconds from System.currentTimeMillis()
divided by 1000:
int seconds = (int)(System.currentTimeMillis() / 1000);
Although the long
result of the fivusion will fit in an int
variable without loss, the compiler doesn't know this; that's why we need the explicit cast.
Upvotes: 1