用formatdatetime('这里日期时间的格式',这里日期时间) 日期格式化函数来搞定以下是帮助: The following example uses FormatDateTime to set the string variable S to a sentence indicating a meeting time in 3 hours. The sentence has the form 'The meeting is on Wednesday, February 15, 1995 at 2:30 PM'. S := FormatDateTime('"The meeting is on " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Now + 0.125);
up 好久没做这事了,帮你顶 楼主是让用户自己输入时间吧, 为什么不用DateTimePicker让时间设置成可选的 也免了检查用户输入时间错误
The following example uses FormatDateTime to set the string variable S to a sentence indicating a meeting time in 3 hours. The sentence has the form 'The meeting is on Wednesday, February 15, 1995 at 2:30 PM'. S := FormatDateTime('"The meeting is on " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Now + 0.125);
好久没做这事了,帮你顶
楼主是让用户自己输入时间吧,
为什么不用DateTimePicker让时间设置成可选的
也免了检查用户输入时间错误
程式执行时只有当我将系统时间格式设置为2005/10/27格式时方可正确执行,其他两种方式则报错,我如何将系统时间格式由2005-10-27或2005.10.27格式设置成为2005/10/27格式. 谢谢
//得到當前系統默認時區的日期
procedure GetDateFormat;
var
sFormatDate:String;
begin
SetLength(sFormatDate,17);//中文時區
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,LOCALE_SLONGDATE ,PChar(sFormatDate),17);
end;
//設置系統日期格式為yyyy-mm-dd
procedure SetDateFormat;
begin
SetLocaleInfoa(LOCALE_SYSTEM_DEFAULT, LOCALE_SLONGDATE, PChar('yyyy-mm-dd'));
end;
FieldByName('icdatetime').Value:=VarToDateTime(Copy(TemDate,1,4)+'/'+Copy(TemDate,5,2)+'/'+Copy(TemDate,7,2)+' '+Copy(TemDate,9,2)+':'+Copy(TemDate,11,2)+':'+Copy(TemDate,13,2));
var
TemDate:string;
t:TDatetime;
begin
TemDate:='2005100711304000003722018';
t:=VarToDateTime(Copy(TemDate,1,4)+'/'+Copy(TemDate,5,2)+'/'+Copy(TemDate,7,2)+' '+Copy(TemDate,9,2)+':'+Copy(TemDate,11,2)+':'+Copy(TemDate,13,2));
ShowMessage(DateTimeToStr(t));
end;
你测试一下吧