Time_T 和 TDatetime

Time_T 表示:距1970-1-1   00:00:00 GMT 标准时间秒数 Longint;

TDateTime: 整数部分为自1899-12-30 以来的天数。其小数部分为天的时间  double型 

 

有些时候可能要互相转换,比如mysql数据库中的时间.

Time_T to TDateTime:

function time_tToDateTime(vtime_t: Integer): TDateTime;
const
  cDeltaDate : Integer = 25569; // 1970/01/01
  cSecPerMint : Integer = 60;
  cSecPerHour : Integer = (60*60);
  cSecPerDay : Integer = (60*60*24);
var
  hh, mm, ss : Word;
  n : Integer;
begin
  {// GMT=+8,格林时间+8时区(北京)}
  vtime_t := vtime_t + cSecPerHour*8 ;
  n := vtime_t mod cSecPerDay;
  hh := n div cSecPerHour;
  n := n mod cSecPerHour;
  mm := n div cSecPerMint;
  ss := n mod cSecPerMint;
  Result := (vtime_t div cSecPerDay) +
    cDeltaDate + EncodeTime(hh, mm, ss, 0);
end;

 

 TDateTime  to Time_T:

function DateTimeTotime_t(dt: TDateTime): LongInt;
begin
  Result := SecondsBetween(dt,25569)-8*3600;
end;


注意: 这里处理的都是北京时间

转载于:https://www.cnblogs.com/doorsky/archive/2009/12/14/1624026.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值