欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2016年03月23日 22:31:28   投稿:mdxy-dxy  
這篇文章主要介紹了python各種語言間時(shí)間的轉(zhuǎn)化,需要的朋友可以參考下

一 基本知識(shí)

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

二 perl

perl中可以使用time或localtime來獲得時(shí)間,time返回從1970年1月1日0點(diǎn)的秒數(shù),localtime返回當(dāng)前時(shí)間的字符串表示,或者年月日等得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進(jìn)程的狀態(tài)、創(chuàng)建及使用方法詳解

    python進(jìn)程的狀態(tài)、創(chuàng)建及使用方法詳解

    這篇文章主要介紹了python進(jìn)程的狀態(tài)、創(chuàng)建及使用方法,結(jié)合實(shí)例形式詳細(xì)分析了Python進(jìn)程的概念、原理、工作狀態(tài)、創(chuàng)建以及使用方法,需要的朋友可以參考下
    2019-12-12
  • python深入講解魔術(shù)方法

    python深入講解魔術(shù)方法

    所謂魔法函數(shù)(Magic Methods),是Python的?種?級(jí)語法,允許你在類中?定義函數(shù)(函數(shù)名格式?般為__xx__),并綁定到類的特殊?法中。?如在類A中?定義__str__()函數(shù),則在調(diào)?str(A())時(shí),會(huì)?動(dòng)調(diào)?__str__()函數(shù),并返回相應(yīng)的結(jié)果
    2022-06-06
  • Python+PyQt5實(shí)現(xiàn)開發(fā)Memcached客戶端

    Python+PyQt5實(shí)現(xiàn)開發(fā)Memcached客戶端

    這篇文章主要介紹了如何使用Python和PyQt5來制作一個(gè)Memcached客戶端,以便我們可以輕松地與Memcached服務(wù)器進(jìn)行交互,感興趣的小伙伴可以了解一下
    2023-06-06
  • python3模擬百度登錄并實(shí)現(xiàn)百度貼吧簽到示例分享(百度貼吧自動(dòng)簽到)

    python3模擬百度登錄并實(shí)現(xiàn)百度貼吧簽到示例分享(百度貼吧自動(dòng)簽到)

    這篇文章主要介紹了python3模擬百度登錄并實(shí)現(xiàn)百度貼吧簽到示例,需要的朋友可以參考下
    2014-02-02
  • GitHub上值得推薦的8個(gè)python 項(xiàng)目

    GitHub上值得推薦的8個(gè)python 項(xiàng)目

    GitHub 無疑是代碼托管領(lǐng)域的先行者,Python 作為一種通用編程語言,已經(jīng)被千千萬萬的開發(fā)人員用來構(gòu)建各種有意思或有用的項(xiàng)目。以下我們會(huì)介紹一些使用 Python 構(gòu)建的GitHub上優(yōu)秀的項(xiàng)目。
    2020-10-10
  • 詳解如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù)

    詳解如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù)

    在數(shù)據(jù)處理和分析過程中,經(jīng)常會(huì)遇到需要清洗數(shù)據(jù)的情況,本文將詳細(xì)介紹如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù),感興趣的小伙伴可以了解下
    2024-03-03
  • tensorflow 模型權(quán)重導(dǎo)出實(shí)例

    tensorflow 模型權(quán)重導(dǎo)出實(shí)例

    今天小編就為大家分享一篇tensorflow 模型權(quán)重導(dǎo)出實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Django中如何使用celery異步發(fā)送短信驗(yàn)證碼詳解

    Django中如何使用celery異步發(fā)送短信驗(yàn)證碼詳解

    Celery是Python開發(fā)的分布式任務(wù)調(diào)度模塊,這篇文章主要給大家介紹了關(guān)于Django中如何使用celery異步發(fā)送短信驗(yàn)證碼的相關(guān)資料,主要內(nèi)容包括基礎(chǔ)介紹、工作原理、完整代碼等方面,需要的朋友可以參考下
    2021-09-09
  • Python3 XML 獲取雅虎天氣的實(shí)現(xiàn)方法

    Python3 XML 獲取雅虎天氣的實(shí)現(xiàn)方法

    下面小編就為大家分享一篇Python3 XML 獲取雅虎天氣的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • 使用BeautifulSoup4解析XML的方法小結(jié)

    使用BeautifulSoup4解析XML的方法小結(jié)

    這篇文章主要介紹了使用BeautifulSoup4解析XML的方法小結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12

最新評(píng)論