• Delphi 日期函数的单元 DateUtils


    Delphi DecodeDate和EncodeDate 拆分和聚合时间函数的用法  

     

    SysUtils
    procedure DecodeData(Date: TDateTime; var Year, Month, Day: Word);
    DecodeDate打断TdateTime成为年月日的值。
    DecodeDate打断由Date参数说明的值成为年月日的值。
    如果TDateTime值是小于或等于0,那么返回的年月日值为0;

    这个例子使用一个按纽和两个标签,当按击按钮时,当前的日期和时间就会出现在两个标签的标题中显示。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Present: TDateTime;
    Year, Month, Day, Hour, Min, Sec, MSec: Word;
    begin
    Present := Now;
    DecodeDate(Present, Year, Hour, Day);
      Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
      DecodeTime()Present, Hour, Min, Sec, MSec);
    Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '+ IntToStr(Hour);
    end;

     procedure TForm1.Button1Click(Sender:   TObject);
    var
        Present:   TDateTime;
        Year,   Month,   Day,   Hour,   Min,   Sec,   MSec:   Word;
      begin
        Present:=   Now;
        DecodeDate(Present,   Year,   Month,   Day);
        Label1.Caption   :=   'Today   is   Day   '   +   IntToStr(Day)   +   '   of   Month   '
            +   IntToStr(Month)   +   '   of   Year   '   +   IntToStr(Year);
        DecodeTime(Present,   Hour,   Min,   Sec,   MSec);
        Label2.Caption   :=   'The   time   is   Minute   '   +   IntToStr(Min)   +   '   of   Hour   '
            +   IntToStr(Hour);
    end;
    procedure   TForm1.Button1Click(Sender:   TObject);
    var
        MyDate:   TDateTime;
    begin
        MyDate   :=   EncodeDate(StrToInt(Edit1.Text),   StrToInt(Edit2.Text),   StrToInt(Edit3.Text)); 
        Label1.Caption   :=   DateToStr(MyDate);
    end;

  • 相关阅读:
    项目知识
    设计师如何为 Android 应用标注尺寸
    Android开发注意事项
    线程的同步和异步
    复习:IPC机制
    简单的Mvp设计
    泛型
    RxBus的使用
    LinearLayout遇到的问题——利用LinearLayout做横向滑动冲突
    Google搜索技巧、使用Google的其它专业搜索
  • 原文地址:https://www.cnblogs.com/wanqian/p/3089638.html
Copyright © 2020-2023  润新知