1. System.currentTimeMillis() / 1000 [ 最快 ]
2. new Date().getTime() / 1000
3. Calendar.getInstance().getTimeInMillis() / 1000
点击查看测试结果
JavaScript
Math.round(new Date().getTime()/1000)
Math.round(+new Date() / 1000)
Math.round(Date.now() / 1000) [ 其实都是一种方法 ]
Microsoft .NET / C#
label1.text = datetime.now.hour.tostring() + ':' +datetime.now.minute.tostring() + ':' +datetime.now.second.tostring()。return hkclient.hiks_grabpic(playsession,system.datetime.now.date.tostring() + system.datetime.now.minute.tostring() + system.datetime.now.second.tostring() + ra.next().tostring(), 0)。}unityengine.random.seed = (int)system.datetime.now.touniversaltime().tobinary()。
MySQL
SELECT unix_timestamp(now())
time()
PostgreSQL
SELECT extract(epoch FROM now())
Python
先 import time 然后 time.time()
获取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())
Swift
NSDate().timeIntervalSince1970
import (
"time"
)
int32(time.Now().Unix())
其他操作系统
(如果Perl被安装在系统中)
命令行状态:perl -e "print time"
String date = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(Unix timestamp * 1000))
JavaScript
var timestamp = new date().gettime()。var n=(endtime-new date().gettime())/1000。var date = new date()。
Linux
date -d @Unix timestamp
MySQL
from_unixtime(Unix timestamp)
min hour day month year command。a min hour day month year command。d command year month day hour min。
date('r', Unix timestamp)
PostgreSQL
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + Unix timestamp) * INTERVAL '1 second';
Python
先 import time 然后 time.gmtime(Unix timestamp)
Time.at(Unix timestamp)
SQL Server
DATEADD(s, Unix timestamp, '1970-01-01 00:00:00')
VBScript / ASP
DateAdd("s", Unix timestamp, "01/01/1970 00:00:00")
其他操作系统
(如果Perl被安装在系统中)
$ perl -e "say scalar reverse 'hello'"。before starting, check that your perl version is at least 5.005_03 (or higher) by running the perl -v command. if not,you can install a recent perl interpreter from activeperl (win32) or perl.com (unix/linux/other).。1lunix 时间戳,-e可以让perl程序在perl命令行上运行。
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)
时间格式: YYYY-MM-DD HH:MM:SS 或 YYMMDD 或 YYYYMMDD
先 use Time::Local 然后 my $time = timelocal($sec, $min, $hour, $day, $month,$year);
mktime(hourlunix 时间戳, minute, second, month, day, year)
PostgreSQL
string date = new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date())。 if (date.length() > 10) { sdf = new simpledateformat("yyyy-mm-dd hh:mm:ss")。3 $date.format('yyyy-mm-dd hh:mm:ss',$order.createtime,$locale)
。
Python
先 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)
SQL Server
SELECT DATEDIFF(s, '1970-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)
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-117328-1.html