在python中获取GMT时间戳
我需要获取GMT时间戳,开始一天时的时间戳,而在一天结束时,以下示例是今天的(2022-03-29):
Start of Day (Unix Timestamp): 1648512000
End of Day (Unix Timestamp): 1648598399
您可以在
from datetime import datetime
start_date = datetime.today().strftime('%Y-%m-%d')
start_date += ' 00:00:00'
print(start_date)
timestamp = time.mktime(datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S").timetuple())
print(timestamp)
2022-03-29 00:00:00
1648533600.0
看到这不是我在等待的答案,时间戳是我当地的时间,但是我需要GMT时间戳作为答案(在这种情况下为1648512000)
我该怎么办? 提前致谢!!
I need to get GMT timestamps, a timestamp when start a day, and another when end a day, the following example is for today (2022-03-29):
Start of Day (Unix Timestamp): 1648512000
End of Day (Unix Timestamp): 1648598399
you can check this in https://www.epochconvert.com/
and my code only for the case of start of day is the next one :
from datetime import datetime
start_date = datetime.today().strftime('%Y-%m-%d')
start_date += ' 00:00:00'
print(start_date)
timestamp = time.mktime(datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S").timetuple())
print(timestamp)
and my output:
2022-03-29 00:00:00
1648533600.0
as you can see it's not the answer I'm waiting for, that timestamp is for my Local Time but i need a GMT timestamp as answer (1648512000 in this case)
How could i do it ?
Thanks in Advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要派生 unix time 从dateTime对象中,请确保设置时区域/拥有< em> Aware dateTime:
如果您不这样做(有天真的日期时间),Python将使用 Local Time :
if you want to derive Unix time from datetime objects, make sure to set time zone / have aware datetime:
If you do not do that (have naive datetime), Python will use local time: