I need to get current date & time and convert it to 11 digit unix timestamp.
Just like this site does: http://www.onlineconversion.com/unix_time.htm
I googled a lot but all i could find was timestamp to date conversion problems & answers.
I need to get current date & time and convert it to 11 digit unix timestamp.
Just like this site does: http://www.onlineconversion.com/unix_time.htm
I googled a lot but all i could find was timestamp to date conversion problems & answers.
long unixTime = System.currentTimeMillis() / 1000L;
does what you want. Original answer here.
System.currentTimeMillis() returns the time from the Unix epoch in milliseconds. As 1 second = 1000 milliseconds
, you simply divide it by 1000 to get the time in seconds.
You can use System.currentTimeMillis()
to get the Unix timestamp in milliseconds which you can convert to seconds
long unixTimestamp = System.currentTimeMillis() / 1000L;
If you want to manipulate the date, you can use :
Date myDate = new Date();
myDate.setSeconds(23);
long uTime = myDate.getTime() / 1000L;