delphi日期的使用

delphi中日期的函数大部分都在DateUtil中。

1、获取当年当月当周的第一天和最后一天 函数

uses DateUtils;

function StartOfTheYear(const AValue: TDateTime): TDateTime;  //获取当年的第一天
function EndOfTheYear(const AValue: TDateTime): TDateTime;
function StartOfAYear(const AYear: Word): TDateTime;
function EndOfAYear(const AYear: Word): TDateTime;

function StartOfTheMonth(const AValue: TDateTime): TDateTime;
function EndOfTheMonth(const AValue: TDateTime): TDateTime;
function StartOfAMonth(const AYear, AMonth: Word): TDateTime;
function EndOfAMonth(const AYear, AMonth: Word): TDateTime;

function StartOfTheWeek(const AValue: TDateTime): TDateTime;           {ISO 8601}
function EndOfTheWeek(const AValue: TDateTime): TDateTime;             {ISO 8601}
function StartOfAWeek(const AYear, AWeekOfYear: Word;                  {ISO 8601}
   const ADayOfWeek: Word = 1): TDateTime;
function EndOfAWeek(const AYear, AWeekOfYear: Word;                    {ISO 8601}
   const ADayOfWeek: Word = 7): TDateTime;

2、Example

获取年月日期
procedure TForm1.FormCreate(Sender: TObject);
var
dt: TDateTime;
d: TDate;
t: TTime;
y: Word;
begin
dt := Now;
d := Date;
t := Time;
y := CurrentYear;

ShowMessage(DateTimeToStr(dt)); //2009-5-21 17:45:50
ShowMessage(DateToStr(d)); //2009-5-21
ShowMessage(TimeToStr(t)); //17:45:50
ShowMessage(IntToStr(y)); //2009
end;

转载于:https://www.cnblogs.com/rongxiaoya/archive/2013/01/29/2882011.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值