Timestamp Converter
A timestamp is a sequence of characters or encoded information identifying when a certain event occurred, usually giving date and time of day, sometimes accurate to a small fraction of a second. In computing, it often refers to the number of seconds or milliseconds that have elapsed since the Unix epoch (January 1, 1970, 00:00:00 UTC).
How to Get Current Timestamp in Various Languages
Here are code snippets demonstrating how to obtain the current Unix timestamp (seconds since epoch) or Unix milliseconds timestamp in popular programming languages.
JavaScript
Get current Unix timestamp (seconds):
Math.floor(Date.now() / 1000); // seconds
Get current Unix milliseconds timestamp:
Date.now(); // milliseconds
Python
Get current Unix timestamp (seconds):
import time
int(time.time()) # seconds
Get current Unix milliseconds timestamp:
import time
int(time.time() * 1000) # milliseconds
PHP
Get current Unix timestamp (seconds):
time(); // seconds
Get current Unix milliseconds timestamp:
round(microtime(true) * 1000); // milliseconds
Java
Get current Unix timestamp (seconds):
long unixSeconds = System.currentTimeMillis() / 1000L; // seconds
Get current Unix milliseconds timestamp:
long unixMilliseconds = System.currentTimeMillis(); // milliseconds
C#
Get current Unix timestamp (seconds):
long unixSeconds = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // seconds
Get current Unix milliseconds timestamp:
long unixMilliseconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); // milliseconds