【问题标题】:Create timestamp in Python在 Python 中创建时间戳
【发布时间】:2021-05-07 09:46:07
【问题描述】:

我是 Python 新手。

想知道如何创建时间戳变量。

list_compute_date[0:10]
Out[23]: 
[Timestamp('2021-05-04 00:00:00'),
 Timestamp('2021-04-29 00:00:00'),
 Timestamp('2021-04-28 00:00:00'),
 Timestamp('2021-04-27 00:00:00'),
 Timestamp('2021-04-26 00:00:00'),
 Timestamp('2021-04-23 00:00:00'),
 Timestamp('2021-04-22 00:00:00'),
 Timestamp('2021-04-20 00:00:00'),
 Timestamp('2021-04-19 00:00:00'),
 Timestamp('2021-04-16 00:00:00')]

我有上面的 list_compute_date,现在我要创建一个变量如下:

today = Timestamp('2021-04-28 00:00:00')

然后:

x = list_compute_date[0] - today

print(x) is 6 days.

请帮忙。谢谢!

【问题讨论】:

标签: python datetime


【解决方案1】:
from datetime import datetime

timestamp = datetime.now()
print('timestamp:', timestamp)

https://docs.python.org/3/library/datetime.html

【讨论】:

    猜你喜欢
    • 2018-08-16
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 2013-09-03
    • 2014-12-31
    • 1970-01-01
    • 2010-10-23
    相关资源
    最近更新 更多