python获取当前时间戳的方法:1、使用time模块,语法为“time.time()”;2、使用datetime模块,语法为“datetime.datetime.now().timestamp()”。
使用模块time
1 2 3 4 |
|
使用模块datetime
模块datetime提供了以更面向对象的方式操作日期和时间的类。其中之一是date .datetime。现在返回历元之后的秒数。
1 2 3 4 |
|
使用模块calendar
获取当前时间戳的另一种方法是从多个模块组合多个函数。Python还提供calendar模块。在本例中,我们将使用函数calendar。转换表示当前时间的元组。
1 2 3 4 5 |
|