【发布时间】:2012-09-11 19:01:01
【问题描述】:
我正在尝试使用 Windows GetDateFormat API 函数格式化日期:
nResult = GetDateFormat(
localeId, //0x409 for en-US, or LOCALE_USER_DEFAULT if you're not testing
0, //flags
dt, //a SYSTEMTIME structure
"M/d/yyyy", //the format we require
null, //the output buffer to contain string (null for now while we get the length)
0); //the length of the output buffer (zero while we get the length)
现在我们传递一个日期/时间:
SYSTEMTIME dt;
dt.wYear = 1600;
dt.wMonth = 12;
dt.wDay = 31;
在这种情况下,nResult 返回零:
如果不成功,该函数返回 0。要获取扩展的错误信息,应用程序可以调用 GetLastError,它可以返回以下错误代码之一:
- ERROR_INSUFFICIENT_BUFFER。提供的缓冲区大小不够大,或者被错误地设置为 NULL。
- ERROR_INVALID_FLAGS。为标志提供的值无效。
- ERROR_INVALID_PARAMETER。任何参数值无效。
但是,如果我在一天后返回日期:
SYSTEMTIME dt;
dt.wYear = 1601;
dt.wMonth = 1;
dt.wDay = 1;
然后就可以了。
我做错了什么?如何格式化日期?
例如the birth of Christ的日期:
12/25/0000
或the date when the universe started:
-10/22/4004 6:00 PM
或凯撒去世的日期:
-3/15/44
阅读奖励
【问题讨论】:
-
没有零年。耶稣名义上出生于 0001 年 12 月 25 日。
-
1867 年阿拉斯加没有 10 月 7 日。(当年也没有 10 月 8 日、9 日、10 日、11 日、12 日、13 日、14 日、15 日、16 日或 17 日)
标签: winapi localization internationalization