日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python各种语言间时间的转化

發布時間:2023/12/1 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python各种语言间时间的转化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


一 基本知識

millisecond 毫秒

microsecond 微秒

nanosecond 納秒1秒=1000毫秒 1毫秒=1000微秒 1微秒=1000納秒


?

二 perl

perl中可以使用time或localtime來獲得時間,time返回從1970年1月1日0點的秒數,localtime返回當前時間的字符串表示,或者年月日等得tuple表示。

#!/usr/bin/perl
use?strict;
use?warnings;
use?POSIX?qw(strftime);

#?seconds?from?1970.01.01?00:00:00
my?$ti?=?time();
print?$ti;
print?"\n";
print?strftime("%Y-%m-%d?%H:%M:%S\n",?localtime($ti));
#1310623469
#2011-07-14?14:03:58


my?$t?=?localtime();
print?$t;
print?"\n";
#Thu?Jul?14?12:25:16?2011

my?($sec,?$min,?$hour,?$mday,?$mon,?$year,?$wday,?$yday,?$isdst)=localtime();
print?$year;
print?"\n";
#111

print?strftime("%Y-%m-%d?%H:%M:%S\n",?localtime());
#2011-07-14?12:26:01

?

?

?三 c#

?1tick = 100 nanosecond

using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;

namespace?MyTest
{
????
class?Program
????{
????????
static?void?DateTimeTest()
????????{
????????????DateTime?dt2?
=?DateTime.Now;
????????????Console.WriteLine(dt2.Ticks);
????????????Console.WriteLine(dt2.ToString(
"MM/dd/yyyy?hh:mm:ss"));
????????}

????????
static?DateTime??ConvertPerlTimeToDateTime(string?perltime)
????????{
????????????DateTime
??dt?=?null;
????????????
//perl?time?variable?:?seconds?from?1970.01.01?00:00:00?
????????????string?sdt?=?perltime;
????????????
long?ldt?=?0;
????????????
if?(long.TryParse(sdt,?out?ldt))
????????????{
????????????????
long?ldt2?=?new?DateTime(1970,?1,?1).Ticks?+?ldt?*?1000?*?1000?*?10;
?????????????????dt?
=?new?DateTime(ldt2,?DateTimeKind.Local);
????????????????Console.WriteLine(dt.Value.ToString(
"MM/dd/yyyy?hh:mm:ss"));
????????????}
????????????
return?dt;
????????}

????????
static?void?Main(string[]?args)
????????{
????????????DateTimeTest();
????????????ConvertPerlTimeToDateTime(
"1309423883");
???????????
//634462479788396720
????????????
//07/14/2011?01:46:18
????????????
//06/30/2011?08:51:23
????????}
????}
}

四 python

python的perl相似,time也是從1970年1月1日開始的秒數。

import?time

ISOTIMEFORMAT
='%Y-%m-%d?%X'

#?seconds?from?1970.01.01?00:00:00
t?=?time.time()
print?(t)
print?time.strftime(ISOTIMEFORMAT,time.localtime(t))
#1310623143.12
#
2011-07-14?13:59:03

(year,mon,day,hour,min,sec,wday,yday,isdst)?
=?time.localtime()
print?(year)
print?(time.strftime(ISOTIMEFORMAT,?time.localtime()))
#2011
#
2011-07-14?13:59:03

?

?

完!

?

?

?

?

?

轉載于:https://www.cnblogs.com/itech/archive/2011/07/14/2106212.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python各种语言间时间的转化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。