产品中心 业内新闻 案例中心 视频中心

各种程序处理Unix时间戳(Unix timestamp)方法 各种程序处理Unix时间戳(Unix timestamp)方法

各种程序处理Unix时间戳(Unix timestamp)方法

分类:业内新闻 248

编程程序获取当前时间Unix时间戳(Unix timestamp)方法

Java time
JavaScript Math.round(new Date().getTime()/1000)
getTime()返回数值的单位是毫秒
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时间戳:Time.now    or   Time.new
显示 Unix时间戳:Time.now.to_i
VBScript / ASP DateDiff(“s”, “01/01/1970 00:00:00”, Now())

 

编程程序赋值时间变量为Unix时间戳(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”)
标签:新闻 上一篇: 下一篇:
展开更多
预约软件体验

loading...