編程程序獲取當(dāng)前時(shí)間Unix時(shí)間戳(Unix timestamp)方法
Java | time |
JavaScript | Math.round(new Date().getTime()/1000) |
getTime()返回?cái)?shù)值的單位是毫秒 | |
Unix / Linux | date +%s |
Microsoft .NET / C# | epoch = (DateTime.Now.ToUniversalTime().Ticks – 621355968000000000) / 10000000 |
Python | 1) import time? ? 2) time.time() |
Perl | time |
PHP | time() |
MySQL | SELECT unix_timestamp(now()) |
PostgreSQL | SELECT extract(epoch FROM now()) |
SQL Server | SELECT DATEDIFF(s, ‘1970-01-01 00:00:00’, GETUTCDATE()) |
Ruby | 獲取 Unix時(shí)間戳:Time.now? ? or? ?Time.new |
顯示 Unix時(shí)間戳:Time.now.to_i | |
VBScript / ASP | DateDiff(“s”, “01/01/1970 00:00:00”, Now()) |
編程程序賦值時(shí)間變量為Unix時(shí)間戳(Unix timestamp)方法
Java | String date = new java.text.SimpleDateFormat(“dd/MM/yyyy HH:mm:ss”).format(new java.util.Date(Unix timestamp * 1000)) |
JavaScript | 先 var unixTimestamp = new Date(Unix timestamp * 1000) 然后 commonTime = unixTimestamp.toLocaleString() |
Linux | date -d @Unix timestamp |
Perl | 1)my $time = Unix timestamp? 2)my ($sec, $min, $hour, $day, $month, $year) = (localtime($time))[0,1,2,3,4,5,6] |
PHP | date(‘r’, Unix timestamp) |
MySQL | from_unixtime(Unix timestamp) |
PostgreSQL | SELECT TIMESTAMP WITH TIME ZONE ‘epoch’ + Unix timestamp) * INTERVAL ‘1 second’; |
Python | 1) import time? ? 2) time.gmtime(Unix timestamp) |
SQL Server | DATEADD(s, Unix timestamp, ‘1970-01-01 00:00:00’) |
Ruby | Time.at(Unix timestamp) |
VBScript / ASP | DateAdd(“s”, Unix timestamp, “01/01/1970 00:00:00”) |