Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #326 Milliseconds since Unix epoch

Assign to t the number of milliseconds elapsed since 00:00:00 UTC on 1 January 1970.

#include <chrono>
auto t = std::chrono::milliseconds(std::chrono::system_clock::now().time_since_epoch()).count();
import "time"
t := time.Now().UnixMilli()
import static java.lang.System.currentTimeMillis;
long t = currentTimeMillis();
import java.util.Date;
long t = new Date().getTime();
import java.time.Instant;
long t = Instant.now().toEpochMilli();
dateutils
t := DateTimeToUnix(Now);
use Time::HiRes;
$t = Time::HiRes::time * 1000;
import time
t = time.time() * 1000
t = 1000 * Time.now.to_f

New implementation...
< >
programming-idioms.org