編程中獲取Unix時間戳

Java
time
JavaScript
Math.round(new Date().getTime()/1000)
getTime()返回數值的單位是毫秒
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 而後 time.time()
Ruby
獲取Unix時間戳:Time.now 或 Time.new
顯示Unix時間戳:Time.now.to_i
SQL Server
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
Unix / Linux
date +%s
VBScript / ASP
DateDiff("s", "01/01/1970 08:00:00", Now())
lua os.time() 返回時間戳
其餘操做系統
(若是Perl被安裝在系統中)
命令行狀態:perl -e "print time"
相關文章
相關標籤/搜索