zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    这些诗词你知道一句,却不知全诗!
    二十二、事件绑定及深入
    二十一、事件对象
    二十、事件入门
    十九、动态加载脚本和样式
    十八、DOM元素尺寸和位置
    十七、DOM操作表格及样式
    十六、DOM进阶
    十五、DOM基础
    正确使用volatile场景--状态标志
  • 原文地址:https://www.cnblogs.com/rongxiaoya/p/2882011.html
Copyright © 2011-2022 走看看