菜鸟教程 -- 学的不仅是技术,更是梦想!

Python 基础教程
(追記) (追記ここまで)

Python time time()方法


描述

Python time time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数)。

语法

time()方法语法:

time.time()

参数

  • NA。

返回值

返回当前时间的时间戳(1970纪元后经过的浮点秒数)。

实例

以下实例展示了 time() 函数的使用方法:

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

以上实例输出结果为:

time.time(): 1234892919.655932
(2009, 2, 17, 10, 48, 39, 1, 48, 0)
Tue Feb 17 10:48:39 2009
AI 思考中...

1 篇笔记 写笔记

  1. #0

    Drac0nids

    166***[email protected]

    197

    利用time.time()方法,我们可以计算两个时间点之间的间隔,但是有些时候我们想要得到当前的年月日这些信息,那么在python中该怎么做呢?方法如下:

    >>> import time()
    >>> print time.time()
    1518068251.33
    >>> time = time.localtime(time.time())
    >>> print time
    time.struct_time(tm_year=2018, tm_mon=2, tm_mday=8, tm_hour=13, tm_min=37, tm_sec=31, tm_wday=3, tm_yday=39, tm_isdst=0)
    >>> print time.tm_year
    2018
    >>> print time.tm_mon
    2

    通过上面的方法我们就可以得到年月日等信息了

    Drac0nids

    166***[email protected]

    9年前 (2018年02月08日)

点我分享笔记

  • 昵称 (必填)
  • 邮箱 (必填)
  • 引用地址

AltStyle によって変換されたページ (->オリジナル) /