时间函数

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var
  dt,t1,t2,t3,t4: TDateTime;
  s1,s2,s3,s4: string;
begin
  dt := StrToDateTime('2009-5-20 11:22:33');

  t1 := StartOfAYear(2009);
  t2 := StartOfTheYear(dt);
  t3 := EndOfAYear(2009);
  t4 := EndOfTheYear(dt);

  s1 := FormatDateTime('yyyy-m-d h:n:s:zzz', t1); //2009-1-1 0:0:0:000
  s2 := FormatDateTime('yyyy-m-d h:n:s:zzz', t2); //2009-1-1 0:0:0:000
  s3 := FormatDateTime('yyyy-m-d h:n:s:zzz', t3); //2009-12-31 23:59:59:999
  s4 := FormatDateTime('yyyy-m-d h:n:s:zzz', t4); //2009-12-31 23:59:59:999

  t1 := StartOfAMonth(2009, 5); { 2009 年 5 月 }
  t2 := StartOfTheMonth(dt);
  t3 := EndOfAMonth(2009, 5);
  t4 := EndOfTheMonth(dt);

  s1 := FormatDateTime('yyyy-m-d h:n:s:zzz', t1); //2009-5-1 0:0:0:000
  s2 := FormatDateTime('yyyy-m-d h:n:s:zzz', t2); //2009-5-1 0:0:0:000
  s3 := FormatDateTime('yyyy-m-d h:n:s:zzz', t3); //2009-5-31 23:59:59:999
  s4 := FormatDateTime('yyyy-m-d h:n:s:zzz', t4); //2009-5-31 23:59:59:999

  t1 := StartOfAWeek(2009, 21); { 2009 年第 21 周 }
  t2 := StartOfTheWeek(dt);
  t3 := EndOfAWeek(2009, 21);
  t4 := EndOfTheWeek(dt);

  s1 := FormatDateTime('yyyy-m-d h:n:s:zzz', t1); //2009-5-18 0:0:0:000
  s2 := FormatDateTime('yyyy-m-d h:n:s:zzz', t2); //2009-5-18 0:0:0:000
  s3 := FormatDateTime('yyyy-m-d h:n:s:zzz', t3); //2009-5-24 23:59:59:999
  s4 := FormatDateTime('yyyy-m-d h:n:s:zzz', t4); //2009-5-24 23:59:59:999

  t1 := StartOfADay(2009, 140); { 2009 年第 140 天 }
  t2 := StartOfTheDay(dt);
  t3 := EndOfADay(2009, 140);
  t4 := EndOfTheDay(dt);

  s1 := FormatDateTime('yyyy-m-d h:n:s:zzz', t1); //2009-5-20 0:0:0:000
  s2 := FormatDateTime('yyyy-m-d h:n:s:zzz', t2); //2009-5-20 0:0:0:000
  s3 := FormatDateTime('yyyy-m-d h:n:s:zzz', t3); //2009-5-20 23:59:59:999
  s4 := FormatDateTime('yyyy-m-d h:n:s:zzz', t4); //2009-5-20 23:59:59:999
end;

end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值