views:

248

answers:

1

i know Win32 has the Nls function GetDateFormat, e.g.:

GetDateFormat(…, …, …, "dddd','MM','y", …, …);

and it has GetTimeFormat, e.g.:

GetTimeFormat(…, …, …, "tt ss':'hh':'mm", …, …);

But there a way to format both at once, e.g.:

GetDateTimeFormat(…, …, …, "tt dddd' - 'ss':'y';'hh':'mm MM", …, …);

Note: The format string is intentionally constructed to demonstrate that not all format strings are linearly seperable.

+1  A: 

I remember having the same problem sometime ago. Unfortunately, there's no easy way to format a string with mixed date and time fields. Trying to do it in two steps is error prone, since the first substitution might generate words whose letters are mistaken for format codes.

My solution at the time was to scan the format string manually and generate the output by calling GetDateFormat() and GetTimeFormat() for each code. This can be optimized by grouping consecutive time or date codes if needed.

efotinis