Delphi 判断时间是否合法 -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.

posted @ 2014-03-06 20:59  Max Woods  阅读(663)  评论(0编辑  收藏  举报