起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 411|回复: 4

【结贴】DateUtils.StartOfTheDay 和DateUtils.StartOfADay分别代表什么意思?

[复制链接]
发表于 2010-10-21 09:53:47 | 显示全部楼层 |阅读模式
如题。
回复

使用道具 举报

发表于 2010-10-21 10:16:35 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-10-21 10:27:08 | 显示全部楼层

谢谢zfang,讲很详细,我把帖子转过来

StartOfAYear ... StartOfTheYear ... EndOfAYear ... EndOfTheYear ... 每年、月、周、日的开始与结束的时间
{参数是指定的年、月、周、日}
DateUtils.StartOfAYear
DateUtils.StartOfAMonth
DateUtils.StartOfAWeek
DateUtils.StartOfADay

{参数是 TDateTime}
DateUtils.StartOfTheYear
DateUtils.StartOfTheMonth
DateUtils.StartOfTheWeek
DateUtils.StartOfTheDay

{参数是指定的年、月、周、日}
DateUtils.EndOfAYear
DateUtils.EndOfAMonth
DateUtils.EndOfAWeek
DateUtils.EndOfADay

{参数是 TDateTime}
DateUtils.EndOfTheYear
DateUtils.EndOfTheMonth
DateUtils.EndOfTheWeek
DateUtils.EndOfTheDay
--------------------------------------------------------------------------------


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;
回复 支持 反对

使用道具 举报

发表于 2010-10-21 10:31:11 | 显示全部楼层
呵呵,那结贴了?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-10-21 10:57:39 | 显示全部楼层
好,结贴。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-6 18:07 , Processed in 0.040043 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表