- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我最近在日期转换方面遇到了问题。运行我的应用程序的某些工作站无法将字符串正确转换为日期。
我将问题追溯到似乎没有检查 LOCALE_SSHORTDATE 以进行转换的 VarDateFromStr。我想知道是否有人知道它为转换检查了什么。或者不同的行为是否只链接到不同的 DLL 版本?
GetLocaleStr(GetThreadLocale, LOCALE_SSHORTDATE, 'm/d/yy'); // returns 'dd-MM-yyyy'
FormatDateTime('dd-MM-yyyy', VarToDateTime('05-11-2010')); //returns '11-05-2010'
编辑:有人告诉我,将短日期格式(在控制面板中)从“dd-MM-yyyy”更改为 whatever 然后再更改回“dd-MM-yyyy”可以解决问题。不过,我仍然需要验证这一点。
EDIT2:有点忘了提,这个问题只在 WinXP SP3 上得到确认。
最佳答案
肯 VarToDateTime
函数内部调用 VarDateFromStr
使用 VAR_LOCALE_USER_DEFAULT
的函数格式化日期的常量。
要确定哪种格式包含 VAR_LOCALE_USER_DEFAULT
,您可以使用此代码
var
FormatSettings : TFormatSettings;
begin
GetLocaleFormatSettings(VAR_LOCALE_USER_DEFAULT, formatSettings);
ShowMessage('VarToDateTime is using this format to convert dates '+formatSettings.ShortDateFormat);
end;
现在为了避免您的问题,您可以使用 StrToDateTime 函数将变体值转换为字符串,然后再转换为日期时间
var
v : variant;
FormatSettings : TFormatSettings;
Begin
v:='05-11-2010';//this is your variant.
FormatSettings.ShortDateFormat:='dd-mm-yyyy';//use this format in the conversion
ShowMessage(FormatDateTime('dd-MM-yyyy', StrToDateTime(V,FormatSettings)));
end;
关于windows - VarToDateTime(VarDateFromStr) 使用哪种日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4070105/
我最近在日期转换方面遇到了问题。运行我的应用程序的某些工作站无法将字符串正确转换为日期。 我将问题追溯到似乎没有检查 LOCALE_SSHORTDATE 以进行转换的 VarDateFromStr。我
这是 that question 的跟进. 正如所问,当 VAR_LOCALE_USER_DEFAULT 作为参数提供时,是什么导致 VarDateFromStr(来自 Oleaut32.dll)无法
我是一名优秀的程序员,十分优秀!