I inherited a TCL script (I have zero familiarity with the language) and need to add an RFC 3339 timestamp to it:
2012-04-05T12:13:32.123456-08:00
After searching Google, I haven’t found any means of displaying the microseconds or the timezone offset (I have found a way to show the timezone name, but that doesn’t help).
Is there a way to do this without calling an external process?
In TCL8.5, you can try the following command:
That gives you everything except the sub-second resolution. The
clock microsecondscommand will give you the time in microseconds, but I can’t find a format string identifier that matches it. You can use this to build your own command from scratch:Running this results in a timestamp like
2012-04-05T16:35:06.366378-05:00.Edit: Updated code sample to incorporate user1179884’s tweaks (see comments) and to wrap in a proc.