http://tool.chinaz.com/tools/unixtime.aspx
如何在不同程式設計語言中擷取現在的unix時間戳(unix timestamp)?
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
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 00:00:00", now())
其他作業系統
(如果perl被安裝在系統中)
指令行狀态:perl -e "print time"
如何在不同程式設計語言中實作unix時間戳(unix timestamp) → 普通時間?
string date = new java.text.simpledateformat("dd/mm/yyyy hh:mm:ss").format(new java.util.date(unix timestamp * 1000))
先 var unixtimestamp = new date(unix timestamp * 1000) 然後commontime = unixtimestamp.tolocalestring()
linux
date -d @unix timestamp
from_unixtime(unix timestamp)
先 my $time = unix timestamp 然後 my ($sec, $min, $hour, $day, $month, $year) = (localtime($time))[0,1,2,3,4,5,6]
date('r', unix timestamp)
select timestamp with time zone 'epoch' + unix timestamp) * interval '1 second';
先 import time 然後 time.gmtime(unix timestamp)
time.at(unix timestamp)
dateadd(s, unix timestamp, '1970-01-01 00:00:00')
dateadd("s", unix timestamp, "01/01/1970 00:00:00")
指令行狀态:perl -e "print scalar(localtime(unix timestamp))"
如何在不同程式設計語言中實作普通時間 → unix時間戳(unix timestamp)?
long epoch = new java.text.simpledateformat("dd/mm/yyyy hh:mm:ss").parse("01/01/1970 01:00:00");
var commontime = new date(date.utc(year, month - 1, day, hour,minute, second))
select unix_timestamp(time)
時間格式: yyyy-mm-dd hh:mm:ss 或 yymmdd 或 yyyymmdd
先 use time::local 然後 my $time = timelocal($sec, $min, $hour, $day, $month, $year);
mktime(hour, minute, second, day, month, year)
select extract(epoch from date('yyyy-mm-dd hh:mm:ss'));
先 import time 然後 int(time.mktime(time.strptime('yyyy-mm-dd hh:mm:ss', '%y-%m-%d %h:%m:%s')))
time.local(year, month, day, hour, minute, second)
select datediff(s, '1970-01-01 00:00:00', time)
date +%s -d"jan 1, 1970 00:00:01"
datediff("s", "01/01/1970 00:00:00", time)