A Unix timestamp, also known as Unix time or POSIX time, represents the number of seconds that have elapsed since January 1, 1970, at 00:00:00 UTC, not counting leap seconds. This standardized time representation is widely used in computing and forms the basis for time-related calculations in many systems.
The concept of Unix time was introduced with the Unix operating system and has since been adopted by many other systems. It provides a simple and unambiguous way to represent a point in time, independent of time zones or other local variations.
For more information, you can refer to the following resources:
Language | Code Example |
---|---|
JavaScript | Math.floor(Date.now() / 1000) |
Python | import time; int(time.time()) |
PHP | time() |
Java | (int) (System.currentTimeMillis() / 1000) |
C# | DateTimeOffset.UtcNow.ToUnixTimeSeconds() |
C | #include <time.h> time(NULL) |
Go | import "time" int(time.Now().Unix()) |
Unix Shell | date +%s |
Language | Code Example |
---|---|
JavaScript | Math.floor(new Date('2023-04-15T12:00:00').getTime() / 1000) |
Python | import datetime; int(datetime.datetime(2023, 4, 15, 12, 0).timestamp()) |
PHP | strtotime('2023-04-15 12:00:00') |
Java | LocalDateTime.of(2023, 4, 15, 12, 0).toEpochSecond(ZoneOffset.UTC) |
C# | new DateTimeOffset(2023, 4, 15, 12, 0, 0, TimeSpan.Zero).ToUnixTimeSeconds() |
C | #include <time.h> struct tm t = {0}; strptime("2023-04-15 12:00:00", "%Y-%m-%d %H:%M:%S", &t); time_t epoch = mktime(&t); |
Go | import "time" t, _ := time.Parse("2006-01-02 15:04:05", "2023-04-15 12:00:00") int(t.Unix()) |
Unix Shell | date -d "2023-04-15 12:00:00" +%s |
Language | Code Example |
---|---|
JavaScript | new Date(1681560000 * 1000).toUTCString() |
Python | import datetime; datetime.datetime.utcfromtimestamp(1681560000).strftime('%Y-%m-%d %H:%M:%S') |
PHP | date('Y-m-d H:i:s', 1681560000) |
Java | Instant.ofEpochSecond(1681560000).atZone(ZoneOffset.UTC).toString() |
C# | DateTimeOffset.FromUnixTimeSeconds(1681560000).ToString("yyyy-MM-dd HH:mm:ss") |
C | #include <time.h> time_t epoch = 1681560000; struct tm *t = gmtime(&epoch); char buffer[30]; strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", t); |
Go | import "time" time.Unix(1681560000, 0).UTC().Format("2006-01-02 15:04:05") |
Unix Shell | date -u -d @1681560000 "+%Y-%m-%d %H:%M:%S" |