从 IANA 到 Windows ID 的 ICU 时区转换在 Windows 中不起作用
因此,我一直在尝试在 C++ 中将 IANA 时区转换为 Windows ID。这是我的示例代码。
#include <ucal.h>
#include <wchar.h>
#include <string.h>
int main()
{
wchar_t buffer[128];
UErrorCode status;;
DWORD dwResult = 0;
DWORD iterator = 0;
DYNAMIC_TIME_ZONE_INFORMATION dynamicTimezone = { 0 };
DWORD i = 0;
printf("\n\n\n");
int length = 128;
char tz_info[128] = "America/New_York";
size_t len = strlen(tz_info) + 1;
wchar_t text_wchar[128];
mbstowcs_s(0, text_wchar, len, tz_info, _TRUNCATE);
auto result = ucal_getWindowsTimeZoneID(text_wchar, -1, buffer, ARRAYSIZE(buffer), &status);
if (U_SUCCESS(status)) {
printf("result = %d, Windows %ls:%s <- IANA %ls\n",
result, buffer, "None", text_wchar);
}
else {
printf("FAILED");
}
return 0;
}
现在,当我使用“icu.h”标头并包含系统库 icuuc.lib 和 icuin.lib 时,上面的代码可以工作。但是,在我的项目中,我想使用自定义构建 icu (v63),但是当我使用自定义构建的 .libs
和 .dlls
时,该函数返回结果长度为 0 并且缓冲区中没有任何内容。
我没有找到很多关于如何使用自定义构建的 icu 进行时区转换的资源。还有什么需要做或补充的吗?我们需要单独指定或加载数据文件吗?
我不确定数据文件是否需要单独加载,我认为它们是用 icudt.lib 和 icudt.dll 文件加载的。
TIA。
So, I have been trying to convert IANA timezone to windows ID in c++. Here is my sample code.
#include <ucal.h>
#include <wchar.h>
#include <string.h>
int main()
{
wchar_t buffer[128];
UErrorCode status;;
DWORD dwResult = 0;
DWORD iterator = 0;
DYNAMIC_TIME_ZONE_INFORMATION dynamicTimezone = { 0 };
DWORD i = 0;
printf("\n\n\n");
int length = 128;
char tz_info[128] = "America/New_York";
size_t len = strlen(tz_info) + 1;
wchar_t text_wchar[128];
mbstowcs_s(0, text_wchar, len, tz_info, _TRUNCATE);
auto result = ucal_getWindowsTimeZoneID(text_wchar, -1, buffer, ARRAYSIZE(buffer), &status);
if (U_SUCCESS(status)) {
printf("result = %d, Windows %ls:%s <- IANA %ls\n",
result, buffer, "None", text_wchar);
}
else {
printf("FAILED");
}
return 0;
}
Now that above code works when I use "icu.h" header and include the system libraries icuuc.lib and icuin.lib. However, in my project, I would like to use a custom build icu (v63), but when I use the custom built .libs
and .dlls
the function returns a result length of 0 and there is nothing in buffer.
I did not find many resources on how to use custom built icu for timezone conversions. Is there anything else that needs to be done or added? Do we need to specify or load data files separately?
I am not sure if data files needs to be loaded separately, I think they are loaded with icudt.lib
and icudt.dll
file.
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论