詳解Python中time()方法的使用的教程

來源:互聯網
上載者:User
time()方法返回時間,在UTC時代以秒錶示浮點數。

注意:儘管在時間總是返回作為一個浮點數,並不是所有的系統提供時間超過1秒精度。雖然這個函數正常返回非遞減的值,就可以在系統時鐘已經回來了兩次調用期間返回比以前調用一個較低的值。
文法

以下是time()方法的文法:

參數

  • NA

傳回值

此方法返回的時間,因為時代以秒錶示浮點數(在UTC)。
例子

下面的例子顯示time()方法的使用。

#!/usr/bin/pythonimport timeprint "time.time(): %f " % time.time()print time.localtime( time.time() )print time.asctime( time.localtime(time.time()) )

當我們運行上面的程式,它會產生以下結果:

time.time(): 1234892919.655932(2014, 2, 17, 10, 28, 39, 1, 48, 0)Tue Feb 17 10:28:39 2014
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.