菜鸟请问大哥个问题, 我要从MySQL 字段取得的unixtime在DBGrid输出时, 换成(YYYY/MM/DD)该怎么去做啊?
目前底下写法会报错
procedure TForm5.Table1timeGetText(Sender: TField; var Text: TDateTime;
DisplayText: Boolean);
const
cDeltaDate = 25569;
cSecPerMin = 60;
cSecPerHour = (60*60);
cSecPerDay = (60*60*24);function CTimeToDateTime(t:integer):TDatetime;
var
hh,mm,ss:Word;
n:integer;
begin
t:=t+cSecPerHour*8;
n:=t mod cSecPerDay;
hh:=n div cSecPerHour;
n:=n mod cSecPerHour;
mm:=n div cSecPerMin;
ss:=n mod cSecPerMin;
Result:=(t div cSecPerDay)+cDeltaDate+EncodeTime(hh,mm,ss,0);
end;begin
text:=FormatDatetime('yyyy-mm-dd hh:nn:ss',CTimeToDateTime((Sender.AsInteger) div 1000));
displaytext:=true;
end;end.
目前底下写法会报错
procedure TForm5.Table1timeGetText(Sender: TField; var Text: TDateTime;
DisplayText: Boolean);
const
cDeltaDate = 25569;
cSecPerMin = 60;
cSecPerHour = (60*60);
cSecPerDay = (60*60*24);function CTimeToDateTime(t:integer):TDatetime;
var
hh,mm,ss:Word;
n:integer;
begin
t:=t+cSecPerHour*8;
n:=t mod cSecPerDay;
hh:=n div cSecPerHour;
n:=n mod cSecPerHour;
mm:=n div cSecPerMin;
ss:=n mod cSecPerMin;
Result:=(t div cSecPerDay)+cDeltaDate+EncodeTime(hh,mm,ss,0);
end;begin
text:=FormatDatetime('yyyy-mm-dd hh:nn:ss',CTimeToDateTime((Sender.AsInteger) div 1000));
displaytext:=true;
end;end.
解决方案 »
- 100分求一答案:如何在程序中控制IE浏览器打开一指定网址
- 手机短信
- 我想实现:打印一页后暂停,按任意键继续打印。即:每打印一页就暂停一下,直到打印完毕,能实现吗?
- 关于dll的问题(分不够可以再加)
- 用ADO连接Excel中的问题……
- Illegal cursor operation attempt????
- 关于press enter键焦点下移的问题???!!!
- 挺变态的一道面试题,请教高手.
- 无论怎样调整,都是按A4纸打印,真的是无可救药吗?求救!!!
- cxGrid ExportGridToXLSX导出文件打不开
- 立体仓库仿真系统,寻求解决方案
- 在delphi里如何播放.amr的音频格式的文件? 急!
DateUtils;Unix时间转TDateTime:UnixToDateTime
TDateTime转Unix时间:DateTimeToUnix
uses
SysUtils;
procedure Unix2FileTime (const time_in:DWORD ; const pft:PFILETIME);inline;
var
X:Int64;
begin
x := LongLong(time_in) * 10000000 + 116444736000000000;//$19db1ded53ea710;
pft^.dwHighDateTime := DWORD((x shr 32) and $0ffffffff);
pft^.dwLowDateTime := DWORD(x and $0ffffffff);
end;function Unix2DateTime_UTC (const time_in:DWORD ):TDateTime;inline;
var
ft: FILETIME;
st: SYSTEMTIME;
begin
Unix2FileTime(time_in,@ft);
FileTimeToSystemTime(ft,st);
Result := SystemTimeToDateTime(st);
end;function Unix2DateTime (const time_in:DWORD ):TDateTime;inline;
var
ft: FILETIME;
st: SYSTEMTIME;
begin
Unix2FileTime(time_in,@ft);
FileTimeToLocalFileTime(ft,ft);
FileTimeToSystemTime(ft,st);
Result := SystemTimeToDateTime(st);
end;