tcl - Adding/subtracting a second to a UTC timestamp -
i have timestamp data in form of "2013-07-31t13:31:29" need add second to. having issue "clock add" plan convert time epoch time , increment it. when trying noticed times don't seem match each-other.
timestamp: 2013-07-31t13:31:29 epoch time: 1375252289 gmt: wed, 31 jul 2013 06:31:29 gmt
this timestamp generated via tcl code below:
# timeminusmilli == 2013-07-31t13:31:29 set epoch [ clock scan $timeminusmilli -gmt 0 ]
now, maybe i'm confused, think 2013-07-31t13:31:29 wed, 31 jul 2013 1:31:29, not 6:31:29.
the way iso times scanned tcl documented: http://www.tcl.tk/man/tcl8.5/tclcmd/clock.htm#m83
an iso 8601 point-in-time specification, such “ccyymmddthhmmss,” t literal “t”, “ccyymmdd hhmmss”, or “ccyymmddthh:mm:ss”. note these 3 formats accepted. command not accept full range of point-in-time specifications specified in iso8601. other formats can recognized giving explicit -format option clock scan command.
so, either have remove punctuation date part, or specify expected input
% 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
then, manipulate away:
% clock format [clock add $t +1 second] wed jul 31 13:31:30 edt 2013
notice didn't have special interpret time in timezone (edt)
Comments
Post a Comment