Reputation: 463
I'm trying to extract the clock time in Tcl for a string that is formatted as YearMonth like this. "202001" for January 2020.
% set value "202001"
% set clocktime [clock scan $value -format "%Y%m"]
1608537600
You can see that Tcl extracts the epoch time as 1608537600
This isn't correct, as you can see. If I convert that value back to the string value, it comes back as December 2020
% clock format 1608537600 -format "%Y%m"
202012
What am I doing wrong here?
Upvotes: 0
Views: 124
Reputation: 71548
It is specified in the manual (essentially the part that says "The date is determined according to the fields that are present in the preprocessed format string. In order of preference: ...") that if a date is not specified, then the date will be taken as the current date.
Since the date is missing from the clock value provided, clock scan will return the date the script is run as the date. You can try running it with the value 2019
and you will get the same results provided you do it on the same day.
What you could do to avoid that would be to add the date. Appending 01
to the value and %d
to the format string shouldn't be too hard.
Upvotes: 2