IsValidDateTime、IsValidDate、IsValidTime、IsValidDateDay ... 判断时间是否合法

IsValidDateTime、IsValidDate、IsValidTime、IsValidDateDay ... 判断时间是否合法

DateUtils.IsValidDateTime
DateUtils.IsValidDate
DateUtils.IsValidTime
DateUtils.IsValidDateDay
DateUtils.IsValidDateWeek
DateUtils.IsValidDateMonthWeek

//可用下面几个过程抛出异常:
DateUtils.InvalidDateDayError
DateUtils.InvalidDateMonthWeekError
DateUtils.InvalidDateTimeError
DateUtils.InvalidDateWeekError
DateUtils.InvalidDayOfWeekInMonthError

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
  b: Boolean;
begin
  b := IsValidDateTime(2009, 5, 21, 11, 22, 33, 999);  //True
  b := IsValidDateTime(2009, 5, 21, 11, 22, 33, 9999); //False

  b := IsValidDate(2009, 5, 21); //True
  b := IsValidDate(2009, 5, 32); //False

  b := IsValidTime(11, 22, 33, 0); //True
  b := IsValidTime(11, 22, 61, 0); //False

  b := IsValidDateDay(2009, 141); //True
  b := IsValidDateDay(2009, 366); //False

  b := IsValidDateWeek(2009, 21, 7); //True
  b := IsValidDateWeek(2009, 21, 8); //False

  b := IsValidDateMonthWeek(2009, 5, 3, 7); //True
  b := IsValidDateMonthWeek(2009, 5, 3, 8); //False

//  ShowMessage(BoolToStr(b, True));
end;

end.


DateUtils-Function
posted on 2009-05-21 11:29  万一  阅读(4084)  评论(0)  编辑  收藏
上一篇:DateUtils 时间工具类


下一篇:品牌热度定时任务