Thursday, April 18, 2013

Get Unix timestamp in Java, Python, Erlang, JavaScript, Php

To Get Unix timestamp value in seconds
Java:
long timestamp = System.currentTimeMillis()/1000
Python:

import time
timestamp = int(time.time())
Erlang:

{Mega, Secs, _} = now(),
Timestamp = Mega*1000000 + Secs,
JavaScript:

var ts = Math.floor(Date.now()/1000);
// You can also use new Date().getTime()/1000 but this one is faster
Php:
$stamp = time();

No comments:

Post a Comment