Get "unixtime" unix time in Java (Android)

3

The function time () in PHP is the number of seconds since the Unix Era (1 January 1970 00:00:00 GMT).

Example: 1465491771

In java how can you get the equivalent value to Unix Time?

    
asked by Webserveis 09.06.2016 в 19:06
source

2 answers

1

Unix Time in Seconds :

  long millis = System.currentTimeMillis();
  long unixTimeSegs = millis / 1000; 

a shorter version of getting the value:

  long unixTimeSegs = System.currentTimeMillis() / 1000L;

Unix Time in MiliSeconds :

long unixTimeMSegs = System.currentTimeMillis();
    
answered by 09.06.2016 / 21:06
source
1

In PHP

$t=time();

On Android (Java)

long unixTime = System.currentTimeMillis() / 1000L;  // Esto por que unixtime esta en segundos
    
answered by 09.06.2016 в 19:10