python各種語言間時間的轉(zhuǎn)化實現(xiàn)代碼
一 基本知識
millisecond 毫秒
microsecond 微秒
nanosecond 納秒
1秒=1000毫秒 1毫秒=1000微秒 1微秒=1000納秒
二 perl
perl中可以使用time或localtime來獲得時間,time返回從1970年1月1日0點的秒數(shù),localtime返回當(dāng)前時間的字符串表示,或者年月日等得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日開始的秒數(shù)。
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
相關(guān)文章
python進程的狀態(tài)、創(chuàng)建及使用方法詳解
這篇文章主要介紹了python進程的狀態(tài)、創(chuàng)建及使用方法,結(jié)合實例形式詳細(xì)分析了Python進程的概念、原理、工作狀態(tài)、創(chuàng)建以及使用方法,需要的朋友可以參考下2019-12-12Python+PyQt5實現(xiàn)開發(fā)Memcached客戶端
這篇文章主要介紹了如何使用Python和PyQt5來制作一個Memcached客戶端,以便我們可以輕松地與Memcached服務(wù)器進行交互,感興趣的小伙伴可以了解一下2023-06-06python3模擬百度登錄并實現(xiàn)百度貼吧簽到示例分享(百度貼吧自動簽到)
這篇文章主要介紹了python3模擬百度登錄并實現(xiàn)百度貼吧簽到示例,需要的朋友可以參考下2014-02-02詳解如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù)
在數(shù)據(jù)處理和分析過程中,經(jīng)常會遇到需要清洗數(shù)據(jù)的情況,本文將詳細(xì)介紹如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù),感興趣的小伙伴可以了解下2024-03-03tensorflow 模型權(quán)重導(dǎo)出實例
今天小編就為大家分享一篇tensorflow 模型權(quán)重導(dǎo)出實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01Django中如何使用celery異步發(fā)送短信驗證碼詳解
Celery是Python開發(fā)的分布式任務(wù)調(diào)度模塊,這篇文章主要給大家介紹了關(guān)于Django中如何使用celery異步發(fā)送短信驗證碼的相關(guān)資料,主要內(nèi)容包括基礎(chǔ)介紹、工作原理、完整代碼等方面,需要的朋友可以參考下2021-09-09使用BeautifulSoup4解析XML的方法小結(jié)
這篇文章主要介紹了使用BeautifulSoup4解析XML的方法小結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12