What is a UNIX timestamp (
UNIX Timestamp)?
UNIX timestamp, or Unix time or POSIX time, is a time representation, it is defined as the total number of seconds from GMT, January 1, January 01, 1970 to the present. UNIX timestamps are used not only in UNIX and Unix-like systems, but also in many other operating systems.
Currently, a considerable number of operating systems use 32-bit binary numbers to represent the time. The UNIX timestamp of such systems can be used up to GMT, January 1, January 19, 2038 (Binary:01111111 11111111 11111111 11111111). In the next second, the binary number will change10000000 00000000 00000000 00000000An overflow error occurs, causing the system to misunderstand the time as December 13, 1901. This may cause software faults or even system paralysis. Systems that use 64-bit binary numbers to represent time (a maximum of 292,277,026,596 seconds from January 1, December 04 to GMT) will not experience such overflow issues.
How to obtain the current UNIX timestamp in different programming languages (
UNIX Timestamp)?
Java |
Time |
JavasBytes |
Math. Round (new date (). gettime ()/1000) The unit of the value returned by gettime () is millisecond. |
Microsoft. NET/C # |
Epoch = (datetime. Now. touniversaltime (). ticks-621355968000000000)/10000000 |
MySQL |
Select unix_timestamp (now ()) |
Perl |
Time |
PHP |
Time () |
PostgreSQL |
Select extract (epoch from now ()) |
Python |
IMP firstORT time and time. Time () |
Ruby |
Obtain UNIX timestamp: time. Now or time. New Display UNIX timestamp: time. Now. to_ I |
SQL Server |
Select datediff (S, '2017-01-01 00:00:00 ', getutcdate ()) |
Unix/Linux |
Date + % s |
VBScript/asp |
Datediff ("S", "01/01/1970 00:00:00", now ()) |
Other operating systems (If Perl is installed in the System) |
Command Line status: Perl-e "Print time" |
How to Implement UNIX timestamps in different programming languages (
UNIX Timestamp) → Normal time?
Java |
String date = new java. Text. simpledateformat ("DD/MM/YYYY hh: mm: SS"). Format (New java. util. Date (UNIX timestamp * 1000 )) |
JavasBytes |
First var unixtimestamp = new date (UNIX timestamp * 1000) and then commontime = unixtimestamp. tolocalestring () |
Linux |
Date-d @ UNIX Timestamp |
MySQL |
From_unixtime (UNIX timestamp) |
Perl |
First my $ time = UNIX Timestamp and then my ($ sec, $ min, $ hour, $ day, $ month, $ year) = (localtime ($ time) [0, 1, 2, 3, 4, 5, 6] |
PHP |
Date ('R', Unix timestamp) |
PostgreSQL |
Select timestamp with Time Zone 'epoch' + UNIX timestamp) * interval '1 second '; |
Python |
IMP firstORT time and time. gmtime (UNIX timestamp) |
Ruby |
Time. At (UNIX timestamp) |
SQL Server |
Dateadd (S, Unix timestamp, '2017-01-01 00:00:00 ') |
VBScript/asp |
Dateadd ("S", Unix timestamp, "01/01/1970 00:00:00 ") |
Other operating systems (If Perl is installed in the System) |
Command Line status: Perl-e "Print scalar (localtime (UNIX timestamp ))" |
How to implement common time → UNIX timestamp in different programming languages (
UNIX Timestamp)?
Java |
Long epoch = new java. Text. simpledateformat ("DD/MM/YYYY hh: mm: SS"). parse ("01/01/1970 01:00:00 "); |
JavasBytes |
VaR commontime = new date (date. UTC (year, month-1, day, hour, minute, second )) |
MySQL |
Select unix_timestamp (time) Time Format: YYYY-MM-DD hh: mm: SS or yymmdd or yyyymmdd |
Perl |
Use Time: local first and then my $ time = timelocal ($ sec, $ min, $ hour, $ day, $ month, $ year ); |
PHP |
Mktime (hour, minute, second, day, month, year) |
PostgreSQL |
Select extract (epoch from date ('yyyy-MM-DD hh: mm: ss ')); |
Python |
IMP firstORT time and INT (time. mktime (time. strptime ('yyyy-MM-DD hh: mm: ss', '% Y-% m-% d % H: % m: % s '))) |
Ruby |
Time. Local (year, month, day, hour, minute, second) |
SQL Server |
Select datediff (S, '2017-01-01 00:00:00 ', time) |
Unix/Linux |
Date + % s-d "Jan 1, 1970 00:00:01" |
VBScript/asp |
Datediff ("S", "01/01/1970 00:00:00", time) |