python各種語言間時間的轉化

2022-02-18 10:45:37 字數 1950 閱讀 3736

一 基本知識

millisecond 毫秒microsecond 微秒

nanosecond 納秒

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

二 perl

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

#!/usr/bin/perl

usestrict;

usewarnings;

useposix 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 2011my(

$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

static

datetime

?convertperltimetodatetime(

string

perltime)

return

dt;}

static

void

main(

string

args)}}

四 python

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

import

time

isotimeformat='

%y-%m-%d %x'#

seconds from 1970.01.01 00:00:00t =

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

完!   

python各種語言間時間的轉化

一 基本知識 millisecond 毫秒 microsecond 微秒 nanosecond 納秒 1秒 1000毫秒 1毫秒 1000微秒 1微秒 1000納秒 二 perl perl中可以使用time或localtime來獲得時間,time返回從1970年1月1日0點的秒數,localtime...

轉 python時間格式處理

import time import datetime t time.time print t 原始時間資料 print int t 秒級時間戳 print int round t 1000 毫秒級時間戳 print int round t 1000000 微秒級時間戳返回 1499825149.2...

Pyhon Excel時間轉python時間

excel時間轉python時間 excel時間轉python時間 def date dates,t 0 定義轉化日期戳的函式,dates為日期戳 delta timedelta days dates 將1899 12 30轉化為可以計算的時間格式並加上要轉化的日期戳 today datetime....