gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
用DELPHI写一个补充日期时间的函数,如日期时间中有数字只有1位,自动填充0补充为2位,如2023-7-15 9:21:32补充为2023-07-15 09:21:32
- User
用DELPHI写一个补充日期时间的函数,如日期时间中有数字只有1位,自动填充0补充为2位,如2023-7-15 9:21:32补充为2023-07-15 09:21:32
- Assistant
你可以使用FormatDateTime函数来实现日期时间的补充。以下是一个示例函数:
function FormatDateTimePaddingZero(const Value: TDateTime): string; var Year, Month, Day, Hour, Min, Sec, MSec: Word; begin DecodeDateTime(Value, Year, Month, Day, Hour, Min, Sec, MSec); Result := Format('%4d-%.2d-%.2d %.2d:%.2d:%.2d', [Year, Month, Day, Hour, Min, Sec]); end;使用方法:
var DateTimeValue: TDateTime; FormattedDateTime: string; begin DateTimeValue := EncodeDateTime(2023, 7, 15, 9, 21, 32, 0); FormattedDateTime := FormatDateTimePaddingZero(DateTimeValue); ShowMessage(FormattedDateTime); end;运行结果为:2023-07-15 09:21:32