How can I obtain the current UNIX timestamp (UNIX timestamp) in different programming languages )? |
Java |
Time |
Javascript |
Math. Round (new date (). gettime ()/1000) gettime () returns a value in milliseconds. |
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 |
Import time first and then 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" |
|
In different programming languages, how does one implement UNIX timestamp → common time? |
Java |
String date = new java. Text. simpledateformat ("DD/MM/YYYY hh: mm: SS"). Format (New java. util. Date (UNIX timestamp * 1000 )) |
Javascript |
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 |
Import time first and then 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 ))" |
|
In different programming languages, how does one implement normal time → UNIX timestamp )? |
Java |
Long epoch = new java. Text. simpledateformat ("DD/MM/YYYY hh: mm: SS"). parse ("01/01/1970 01:00:00 "); |
Javascript |
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 |
First import time and then 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) |
|