有下面一段語句:
procedure TForm1.Button1Click(Sender: TObject);
begin
try
strtodate(self.Edit1.Text);
except
showmessage('Date error')
end;end;如果我將本機的日期格式設為“日/月/年”
strtodate()只接受“日/月/年”這種格式的日期
如果我將本機的日期格式設為“年/月/日”
strtodate()不接受“日/月/年”這種格式的日期
怎樣能使strtodate()都能接受這兩種日期格式呢?SQL中,將“日/月/年”格式的日期insert 到smalldatetime類型的字段是不是一定不行?
procedure TForm1.Button1Click(Sender: TObject);
begin
try
strtodate(self.Edit1.Text);
except
showmessage('Date error')
end;end;如果我將本機的日期格式設為“日/月/年”
strtodate()只接受“日/月/年”這種格式的日期
如果我將本機的日期格式設為“年/月/日”
strtodate()不接受“日/月/年”這種格式的日期
怎樣能使strtodate()都能接受這兩種日期格式呢?SQL中,將“日/月/年”格式的日期insert 到smalldatetime類型的字段是不是一定不行?
var
pc: pChar;
arr: array[0..30] of char;
begin
pc := new(pchar);
GetLocaleInfo(GetSystemDefaultLCID, LOCALE_SDATE, pc, 5);
CommPubDataU.GLocalDateSep := pc; // 日期的间隔符号 GetLocaleInfo(GetSystemDefaultLCID, LOCALE_STIME, pc, 5);
CommPubDataU.GLocalTimeSep := pc; // 时间的间隔符号 GetLocaleInfo(GetSystemDefaultLCID, LOCALE_SSHORTDATE, arr, 30);
CommPubDataU.GLocalYMDFormat := arr; // 年月日的形式 GetLocaleInfo(GetSystemDefaultLCID, LOCALE_STIMEFORMAT, arr, 30);
CommPubDataU.GLocalHMFormat := arr; // 分秒 的形式
end;你获得后 用function FormatDateTime(const Format: string; DateTime: TDateTime): string; // Format传入 GLocalYMDFormat 即可...
其實你的機子可以用:年/月/日,但是你的輸入框的edit格式設為:日/月/年就可以了
就是strtodate(self.Edit1.Text);這句話能通過
Formatdatetime('yyyy-mm-dd',now());