如何制作 delphi timetostr return 军事时间
how to make delphi timetostr return military time
我正在研究遗留 Delphi 7 程序。当我打电话时
timetostr(now)
我得到一个 12 小时格式的时间字符串,并附有 'AM' 或 'PM' 预告片。
我查看了 Delphi 7 中的帮助文档,并在 Internet 上进行了搜索。结果有点模糊。
根据Wikipedia军用时间是常规的 24 小时制。
为了在 Delphi 中显示,您可以使用 FormatTime
。准确地说:
FormatTime('hh:mm:ss', now)
如果你也想要毫秒那么
FormatTime('hh:mm:ss.zzz', now)
您可以使用 TFormatSettings 变量:
var
AFormat: TFormatSettings;
...
GetLocaleFormatSettings(-1, AFormat);
AFormat.ShortTimeFormat := 'hh:mm';
AStr := TimeToStr(Now, AFormat);
这将在最近的 Delphi 版本中执行
FormatDateTime('hh:mm:ss', now)
我正在研究遗留 Delphi 7 程序。当我打电话时
timetostr(now)
我得到一个 12 小时格式的时间字符串,并附有 'AM' 或 'PM' 预告片。
我查看了 Delphi 7 中的帮助文档,并在 Internet 上进行了搜索。结果有点模糊。
根据Wikipedia军用时间是常规的 24 小时制。
为了在 Delphi 中显示,您可以使用 FormatTime
。准确地说:
FormatTime('hh:mm:ss', now)
如果你也想要毫秒那么
FormatTime('hh:mm:ss.zzz', now)
您可以使用 TFormatSettings 变量:
var
AFormat: TFormatSettings;
...
GetLocaleFormatSettings(-1, AFormat);
AFormat.ShortTimeFormat := 'hh:mm';
AStr := TimeToStr(Now, AFormat);
这将在最近的 Delphi 版本中执行
FormatDateTime('hh:mm:ss', now)