如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)

前端之家收集整理的这篇文章主要介绍了如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何在不同编程语言中获取现在的Unix时间戳(Unixtimestamp)?

@H_403_14@Java

@H_403_14@time

@H_403_14@JavaScript

@H_403_14@Math.round(new Date().getTime()/1000)
getTime()@H_403_14@返回数值的单位是毫秒

@H_403_14@Microsoft .NET / C#

@H_403_14@epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000

@H_403_14@MysqL

@H_403_14@SELECT unix_timestamp(now())

@H_403_14@Perl

@H_403_14@time

@H_403_14@PHP

@H_403_14@time()

@H_403_14@Postgresql

@H_403_14@SELECT extract(epoch FROM now())

@H_403_14@Python

@H_403_14@先import time然后time.time()

@H_403_14@Ruby

@H_403_14@获取Unix时间戳:Time.now或Time.new
显示Unix时间戳:Time.now.to_i

@H_403_14@sql Server

@H_403_14@SELECT DATEDIFF(s,'1970-01-01 00:00:00',GETUTCDATE())

@H_403_14@Unix / Linux

@H_403_14@date +%s

@H_403_14@VBScript / ASP

@H_403_14@DateDiff("s","01/01/1970 00:00:00",Now())

@H_403_14@其他操作系统
@H_403_14@(@H_403_14@如果Perl被安装在系统中)

@H_403_14@命令行状态:perl -e "print time"


如何在不同编程语言中实现Unix时间戳(Unixtimestamp) → 普通时间?

@H_403_14@Java

@H_403_14@String date =

@H_403_14@new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date(Unix timestamp* 1000))

@H_403_14@JavaScript

@H_403_14@先var unixTimestamp =

@H_403_14@new Date(Unix timestamp* 1000)然后commonTime = unixTimestamp.toLocaleString()

@H_403_14@Linux

@H_403_14@date -d @Unix timestamp

@H_403_14@MysqL

@H_403_14@from_unixtime(Unix timestamp)

@H_403_14@Perl

@H_403_14@先my $time =Unix timestamp

然后my ($sec,$min,$hour,$day,$month,$year) = (localtime($time))[0,1,2,3,4,5,6]

@H_403_14@PHP

@H_403_14@date('r',Unix timestamp)

@H_403_14@Postgresql

@H_403_14@SELECT TIMESTAMP WITH TIME ZONE 'epoch' +Unix timestamp) * INTERVAL '1 second';

@H_403_14@Python

@H_403_14@先import time然后time.gmtime(Unix timestamp)

@H_403_14@Ruby

@H_403_14@Time.at(Unix timestamp)

@H_403_14@sql Server

@H_403_14@DATEADD(s,Unix timestamp,'1970-01-01 00:00:00')

@H_403_14@VBScript / ASP

@H_403_14@DateAdd("s","01/01/1970 00:00:00")

@H_403_14@其他操作系统
@H_403_14@(@H_403_14@如果Perl被安装在系统中)

@H_403_14@命令行状态:perl -e "print scalar(localtime(Unix timestamp))"


如何在不同编程语言中实现普通时间 → Unix时间戳(Unixtimestamp)?

@H_403_14@Java

@H_403_14@long epoch =

@H_403_14@new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse("01/01/1970 01:00:00");

@H_403_14@JavaScript

@H_403_14@var commonTime = new Date(Date.UTC(year,month- 1,day,hour,minute,second))

@H_403_14@MysqL

@H_403_14@SELECT unix_timestamp(time)
@H_403_14@时间格式: YYYY-MM-DD HH:MM:SS 或 YYMMDD 或 YYYYMMDD

@H_403_14@Perl

@H_403_14@先use Time::Local然后my $time = timelocal($sec,$year);

@H_403_14@PHP

@H_403_14@mktime(hour,second,month,year)

@H_403_14@Postgresql

@H_403_14@SELECT extract(epoch FROM date('YYYY-MM-DD HH:MM:SS'));

@H_403_14@Python

@H_403_14@先import time

然后int(time.mktime(time.strptime('YYYY-MM-DD HH:MM:SS','%Y-%m-%d %H:%M:%S')))

@H_403_14@Ruby

@H_403_14@Time.local(year,second)

@H_403_14@sql Server

@H_403_14@SELECT DATEDIFF(s,time)

@H_403_14@Unix / Linux

@H_403_14@date +%s -d"Jan 1,1970 00:00:01"

@H_403_14@VBScript / ASP

@H_403_14@DateDiff("s",time)

原文链接:https://www.f2er.com/bash/392372.html

猜你在找的Bash相关文章