Getting numeric timezone in specified format Getting numeric timezone in specified format unix unix

Getting numeric timezone in specified format


You would have to manually split the string which is formated by %z as +hhmm or -hhmm. %z has a fixed format. Look at the description of strftime.

Replaced by the offset from UTC in the ISO 8601:2000 standard format ( +hhmm or -hhmm ), or by no characters if no timezone is determinable.

Build one string with date and time. Build a second string with the offset from UTC with %z, insert the : in the second string. Concatenate first and second string.


It tries to interpret %: and it doesn't match a format specifier, so it prints it out as is. But you probably knew that already =)

In your time_to_string function, I would manually insert the ':' into the buffer before displaying it.


The syntax you tried don't exist.

What I would do is calling the function twice : once with "%Y-%m-%d %H%M%S ", and once with "%z", manually add the : in the second string, and then concatenate the two.

To insert the :, you could do an ugly buffer manipulation :

buf2[5]=buf2[4];buf2[4]=buf2[3];buf2[3]=':';strcat(buf,buf2);

Note that the layout isn't likely to change for this specific data, so it's not so ugly.

0r if you really like overkill, a regexp. But you'll need an external library.