how to get the number of seconds passed since 1970 for a date value?

前端 未结 2 462
执念已碎
执念已碎 2020-12-16 09:15

I have to an android application in which I need to convert the current date to the number of seconds passed since 1970.

What I am doing currently i

相关标签:
2条回答
  • 2020-12-16 09:37

    System.currentTimeMillis() gives you the number of milliseconds since the Unix epoch (January 1, 1970 00:00:00 UTC).

    Divide it by 1000 to get the number of seconds.

    0 讨论(0)
  • 2020-12-16 09:39
    //long currentTimeMillis ()-Returns the current time in milliseconds. 
    long millis = System.currentTimeMillis();
    
    //Divide millis by 1000 to get the number of seconds.
    long seconds = millis / 1000;
    
    0 讨论(0)
提交回复
热议问题