最近有一個任務(使用Delphi開發),需要獲取時間,並且精確到毫秒,並以人性化的方式展示出來,比如2015-08-17 19:32:00 800
var
currentTime:TSystemTime;
year, month, day, hour, minute, second, millisecond: string;
datetime: string;
begin
GetSystemTime(currentTime);
year:= IntToStr(currentTime.wYear);
month:= IntToStr(currentTime.wMonth);
day:= IntToStr(currentTime.wDay);
hour:= IntToStr(currentTime.wHour);
minute:= IntToStr(currentTime.wMinute);
second:= IntToStr(currentTime.wSecond);
millisecond:= IntToStr(currentTime.wMilliseconds);
datetime:= year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second + ':' + millisecond;
ShowMessage(datetime);
end;
其中TSystemTime的定義為
PSystemTime = ^TSystemTime;
_SYSTEMTIME = record
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
end;
{$EXTERNALSYM _SYSTEMTIME}
TSystemTime = _SYSTEMTIME;
SYSTEMTIME = _SYSTEMTIME;
{$EXTERNALSYM SYSTEMTIME}