问题描述
- Delphi的怎么获取当前的时间并且转换为精确到毫秒
-
最近有一个任务(使用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}
解决方案二:
sqlite 获取当前时间 精确到毫秒
VC获取系统时间、程序运行时间(精确到秒,毫秒)
获取时间精确到毫秒
解决方案三:
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;
Form1.mmo1.Lines.Add(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}