开发者

Does Win32 provide a GetDateTimeFormat to obtain a unified date-time string, in analogy to GetDateFormat and GetTimeFormat?

开发者 https://www.devze.com 2022-12-22 23:14 出处:网络
I know Win32 has the NLS function GetDateFormat, e.g.: GetDateFormat(…, …, …, "dddd\',\'MM\',\'y", …, …);

I know Win32 has the NLS function GetDateFormat, e.g.:

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

and it also has the function GetTimeFormat, e.g.:

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

But 开发者_如何学编程is there a way to format both the date and time at once, like a hypothetical GetDateTimeFormat function?

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

Note: The format string is intentionally constructed to demonstrate that not all format strings are linearly separable. Thus, this is not the trivial problem that it appears to simply concatenate the results of GetDateFormat and GetTimeFormat.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号