国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python各種語言間時間的轉(zhuǎn)化實現(xiàn)代碼

2020-01-04 17:35:15
字體:
供稿:網(wǎng)友
這篇文章主要介紹了python各種語言間時間的轉(zhuǎn)化,需要的朋友可以參考下
 

一 基本知識

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

二 perl

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

#!/usr/bin/perluse strict;use warnings;use POSIX qw(strftime);# seconds from 1970.01.01 00:00:00my $ti = time();print $ti;print "/n";print strftime("%Y-%m-%d %H:%M:%S/n", localtime($ti));#1310623469#2011-07-14 14:03:58my $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";#111print 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日開始的秒數(shù)。

import timeISOTIMEFORMAT='%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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 凯里市| 邵武市| 泾源县| 蓬溪县| 清镇市| 隆子县| 旺苍县| 大英县| 巨鹿县| 乌兰察布市| 阳城县| 阿图什市| 土默特左旗| 北京市| 惠来县| 保定市| 岐山县| 辉南县| 河北省| 建昌县| 团风县| 札达县| 黄山市| 巨鹿县| 三江| 宁乡县| 泸西县| 永平县| 宜良县| 长岛县| 巴里| 万荣县| 乐亭县| 本溪市| 连云港市| 福清市| 大足县| 汾西县| 福安市| 延安市| 维西|