Search code examples
javaandroidunix-timestamp

Android DateTime to 11 digit Unix Timestamp


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.


Solution

  • 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.