时间戳转换工具(Unix timestamp),开发者工具,支持时区切换

当前时间
1600000000
暂停 复制
时间戳转换
获取时间戳
秒转天、小时、分钟、秒

示例代码:

获取时间戳
语言(language)
代码(code)
Java
long epoch = System.currentTimeMillis()/1000
JavaScript
Math.floor(new Date().getTime()/1000)
PHP
time()
Python
import time;
time.time()
Ruby
Time.now (or Time.new)
Go
time.Now().Unix()
MySQL
SELECT unix_timestamp(now())
PowerShell
[int][double]::Parse((Get-Date (get-date).touniversaltime() -UFormat %s))
SQL Server
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
C#
DateTimeOffset.Now.ToUnixTimeSeconds() (.NET Framework 4.6+/.NET Core)
旧版本: var epoch = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds
C++11
double now = std::chrono::duration_cast<std::chrono::second>(std::chrono::system_clock::now().time_since_epoch()).count()
Perl
time
Objective-C
[[NSDate date] timeIntervalSince1970]; (returns double) or NSString *currentTimestamp = [NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]];
Lua
epoch = os.time([date])
AutoIT
_DateDiff('s', "1970/01/01 00:00:00", _NowCalc())
Delphi
Epoch := DateTimetoUnix(Now)
R
as.numeric(Sys.time())
Erlang/OTP
18+版本:system_time(seconds)
旧版本: calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600
PostgreSQL
SELECT extract(epoch FROM now())
SQLite
SELECT strftime('%s', 'now')
Oracle PL/SQL
SELECT (CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE) - TO_DATE('01/01/1970','DD/MM/YYYY')) * 24 * 60 * 60 FROM DUAL
IBM Informix
SELECT dbinfo('utc_current') FROM sysmaster:sysdual
Visual FoxPro
DATETIME() - {^1970/01/01 00:00:00} Warning: time zones not handled correctly
Adobe ColdFusion
<cfset epochTime = left(getTickcount(), 10)>
Tcl/Tk
clock seconds
Unix/Linux Shell
date +%s
字符串转时间戳
语言(language)
代码(code)
Java
long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000
JavaScript
Math.floor(new Date().getTime() / 1000)
PHP
echo stortotime("2020/03/18"))
Python
import calendar, time;
calendar.timegm(time.strptime('2000-01-01 12:34:00', '%Y-%m-%d %H:%M:%S'))
Ruby
Time.local(year, month, day, hour, minute, second, usec )
MySQL
SELECT unix_timestamp(time)
SQL Server
SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
AutoIT
_DateDiff('s', "1970/01/01 00:00:00", "YYYY/MM/DD HH:MM:SS")
Delphi
Epoch := DateTimeToUnix(StrToDateTime(myString))
R
as.numeric(as.POSIXct("YYYY-MM-dd HH:mm:ss", tz = "GMT", origin="1970-01-01"))
PostgreSQL
SELECT extract(epoch FROM date('2000-01-01 12:34'));
With timestamp: SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2018-02-16 20:38:40-08');
With interval: SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours')
SQLite
SELECT strftime('%s',timestring)
Adobe ColdFusion
int(parseDateTime(datetime).getTime()/1000)
Tcl/Tk
clock seconds
Unix/Linux Shell
date +%s -d"Jan 1, 1980 00:00:01"
VBScript/ASP
DateDiff("s", "01/01/1970 00:00:00", time field)
时间戳转字符串
语言(language)
代码(code)
Java
String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000))
JavaScript
new Date()
PHP
echo date(output format, epoch)
Python
import time
timeStamp = 1557502800
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
Ruby
Time.at(epoch)
MySQL
FROM_UNIXTIME()
PowerShell
Function get-epochDate ($epochDate) {
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochDate))
}
SQL Server
DATEADD(s, epoch, '1970-01-01 00:00:00')
C#
private string epoch2string(int epoch) {
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch).ToShortDateString();
}
Objective-C
NSDate * myDate = [NSDate dateWithTimeIntervalSince1970:epoch]; NSLog(@"%@", date)
Lua
datestring = os.date([format[,epoch]])
AutoIT
_DateAdd("s", $EpochSeconds , "1970/01/01 00:00:00")
Delphi
myString := DateTimeToStr(UnixToDateTime(Epoch))
R
as.POSIXct(epoch, origin="1970-01-01", tz="GMT")
PostgreSQL
versions 8.1+: SELECT to_timestamp(epoch)
versions older: SELECT TIMESTAMP WITH TIME ZONE 'epoch' + epoch * INTERVAL '1 second'
SQLite
SELECT datetime(epoch_to_convert, 'unixepoch')
local timezone: SELECT datetime(epoch_to_convert, 'unixepoch', 'localtime')
Oracle PL/SQL
SELECT to_date('01-JAN-1970','dd-mon-yyyy')+(1526357743/60/60/24) from dual
Replace 1526357743 with epoch
IBM Informix
SELECT dbinfo('utc_to_datetime',epoch) FROM sysmaster:sysdual;
Adobe ColdFusion
DateAdd("s",epoch,"1/1/1970");
Tcl/Tk
clock format 1325376000 Documentation
Unix/Linux Shell
date -d @1520000000
什么是Unix时间戳?

Unix时间戳(Unix时间/POSIX时间)是自1970年1月1日(UTC / GMT午夜)以来经过的秒数。

此页面上的转换器将以秒(10位数字)和毫秒(13位数字)为单位的时间戳转换为可读的日期。

单位
数量
1分钟
60
1小时
3600
1天
86400
1周(星期)
604800
1个月(30.44天)
2629743
1年(365.24天)
31556926