[原创] C里面 time() 函数的 delphi 版 ( 积分: 100 )

  • 主题发起人 0000000$
  • 开始时间
0

0000000$

Unregistered / Unconfirmed
GUEST, unregistred user!
function ctime:longword;
const
Days : array [1..12] of integer = (31,28,31,30,31,30,31,31,30,31,30,31);
baseyear:integer = 1970;
//time 从 1970-1-1 00:00:00 开始计时
var
year,month,day,hour,Minutes,second,MilliSecond:word;
totalseconds,totaldays:longword;
begin
//get current date time
decodedatetime(now,year,month,day,hour,Minutes,second,MilliSecond);
if (year < baseyear) then
begin
result := 0;
exit;
end;

totaldays := daysbetween(now,strtodatetime('1970-01-01'));
//view Note.
//add hours
totalseconds := totaldays * 24 + hour - 8;
// -8 , because delphi's now function begin
9:00 am
//add minutes
totalseconds := totalseconds*60 + Minutes ;
//add seconds
totalseconds := totalseconds*60 + second;
//return value
result := totalseconds;
end;
 
function ctime:longword;
const
Days : array [1..12] of integer = (31,28,31,30,31,30,31,31,30,31,30,31);
baseyear:integer = 1970;
//time 从 1970-1-1 00:00:00 开始计时
var
year,month,day,hour,Minutes,second,MilliSecond:word;
totalseconds,totaldays:longword;
begin
//get current date time
decodedatetime(now,year,month,day,hour,Minutes,second,MilliSecond);
if (year < baseyear) then
begin
result := 0;
exit;
end;

totaldays := daysbetween(now,strtodatetime('1970-01-01'));
//view Note.
//add hours
totalseconds := totaldays * 24 + hour - 8;
// -8 , because delphi's now function begin
9:00 am
//add minutes
totalseconds := totalseconds*60 + Minutes ;
//add seconds
totalseconds := totalseconds*60 + second;
//return value
result := totalseconds;
end;
 
啥意思????????????
 
和 C 里面的 Time函数返回一样的东西, 用在时间同步方面..
 
顶部