gpt4 book ai didi

timestamp - 向 UTC 时间戳添加/减去一秒

转载 作者:行者123 更新时间:2023-12-04 04:46:24 26 4
gpt4 key购买 nike

我有一些格式为“2013-07-31T13:31:29”的时间戳数据,我需要添加一秒钟。我在“时钟添加”方面遇到了一些问题,所以我的计划是将时间转换为纪元时间,然后增加它。在尝试这样做时,我注意到时间似乎并不匹配。

Timestamp: 2013-07-31T13:31:29
Epoch time: 1375252289
GMT: Wed, 31 Jul 2013 06:31:29 GMT

此时间戳是通过以下 TCL 代码生成的:
# timeMinusMilli == 2013-07-31T13:31:29
set epoch [ clock scan $timeMinusMilli -gmt 0 ]

现在,也许我只是感到困惑,但我认为 2013-07-31T13:31:29 将是 2013 年 7 月 31 日星期三 1:31:29,而不是 6:31:29。

最佳答案

记录了 Tcl 扫描 ISO 时间的方式:http://www.tcl.tk/man/tcl8.5/TclCmd/clock.htm#M83

An ISO 8601 point-in-time specification, such as “CCyymmddThhmmss,” where T is the literal “T”, “CCyymmdd hhmmss”, or “CCyymmddThh:mm:ss”. Note that only these three formats are accepted. The command does not accept the full range of point-in-time specifications specified in ISO8601. Other formats can be recognized by giving an explicit -format option to the clock scan command.



因此,您要么必须从日期部分中删除标点符号,要么完全指定预期的输入
% set timestr 2013-07-31T13:31:29
2013-07-31T13:31:29
% set t [clock scan [string map {- ""} $timestr]]
1375291889
% set t [clock scan $timestr -format {%Y-%m-%dT%T}]
1375291889
% clock format $t
Wed Jul 31 13:31:29 EDT 2013

然后,操纵离开:
% clock format [clock add $t +1 second]
Wed Jul 31 13:31:30 EDT 2013

请注意,我不需要做任何特别的事情来解释我的时区 (EDT) 中的时间

关于timestamp - 向 UTC 时间戳添加/减去一秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18109982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com