zoukankan      html  css  js  c++  java
  • TDateTime

    8.6 日期时间类
    8.6 日期时间类
    此类函数和过程主要定义在SysUtils 和DateUtils 两个单元。
    8.6.1 获取/合成日期/时间
    function Now: TDateTime;
    返回当前日期和时间。
    function Date: TDateTime;
    返回当前日期。
    function Time: TDateTime;
    返回当前时间。
    function YearOf(const AValue: TDateTime): Word;
    返回指定日期
    /时间的年份。类似的有:
    MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf。
    如果要一次取得其中的多项,可以使用:
    procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
    procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
    procedure DecodeDateTime(DateTime: TDateTime; var Year, Month, Day, Hour,
    Minute, Second, MilliSecond: Word);
    如果要合成一个日期
    /时间,可以使用:
    function EncodeDate(Year, Month, Day: Word): TDateTime;
    function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
    function EncodeDateTime(Year, Month, Day, Hour, Minute, Second,
    MilliSecond: Word): TDateTime;
    procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime);
    更新DateTime 的日期部分。
    procedure ReplaceTime(
    var DateTime: TDateTime; const NewTime: TDateTime);
    更新DateTime 的时间部分。类似的有:
    RecodeYear
    /Month/Day 等等可以更新年份、月份、天等数据。
    8.6.2 日期/时间和字符串的转换
    function DateToStr(Date: TDateTime): string;
    function TimeToStr(Time: TDateTime): string;
    function DateTimeToStr(DateTime: TDateTime): string;
    function StrToDate(const S: string): TDateTime;
    function StrToTime(const S: string): TDateTime;
    function StrToDateTime(const S: string): TDateTime;
    8.6.3 日期/时间的运算
    日期
    /时间数据在本质上是一个浮点数,在System 单元可以看到:
    TDateTime 
    = type Double;
    也就是说,TDateTime 不过是Double 的别名。该数据的整数1 表示一天,如:
    var
    dt: TDateTime;
    begin
    dt :
    = Now; {现在}
    dt :
    = dt + 1{明天}
    dt :
    = dt + 0.25{6 小时后,因为6 小时为0.25 天}
    end;
    VCL 提供以下函数和过程封装了这些原始运算:
    function IncYear(const AValue: TDateTime;
    const ANumberOfYears: Integer = 1): TDateTime;
    对年份运算。类似的有IncMonth、IncDay 等。ANumberOfYears 可以是正数或负数。
    function WeeksInYear(const AValue: TDateTime): Word;
    一年中有多少周。
      
    function DaysInYear(const AValue: TDateTime): Word;
    一年中有多少天。
    function IsInLeapYear(const AValue: TDateTime): Boolean;或者
    function IsLeapYear(Year: Word): Boolean;
    是否是闰年。
    function YearSpan(const ANow, AThen: TDateTime): Double;
    两个日期相差多少年。它假设一年为365.
    25 天。
    function YearsBetween(const ANow, AThen: TDateTime): Integer;
    它是Trunc(YearSpan)(直接取整数,不四舍五入)的结果。
    类似的有MonthSpan
    /sBetween、DaySpan/sBetween、WeekSpan/sBetween、HourSpan/sBetween 等。
    function SystemTimeToDateTime(const SystemTime: TSystemTime):
    TDateTime;
    将一个系统类型时间转化为TDateTime 类型。
    可用API 函数GetSystemTime(SystemTime: PSystemTime)取得系统时间。
  • 相关阅读:
    奇偶游戏(带权并查集)
    银河英雄传说(边带权并查集)
    程序自动分析(并查集+离散化)
    关于树状数组的小总结(树状数组)
    你能回答这些问题吗 (线段树)
    Phython 3 笔记3 —— 类,库与文件的读写
    Phython 3 笔记2 —— 基础语法
    Phython 3 笔记1 —— 基础容器
    CRJ巨佬gjd算法伪代码
    CRJ巨佬的gjd算法模板
  • 原文地址:https://www.cnblogs.com/k1727/p/2099756.html
Copyright © 2011-2022 走看看