请问哪位大侠在delphi中如果知道具体日期,有没有什么函数可以得到星期几?

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);var
      ADate: TDateTime;
      days: array[1..7] of string;
    begin
      days[1] := 'Sunday';
      days[2] := 'Monday';
      days[3] := 'Tuesday';
      days[4] := 'Wednesday';
      days[5] := 'Thursday';
      days[6] := 'Friday';
      days[7] := 'Saturday';
      ADate := StrToDate(Edit1.Text);
      ShowMessage(Edit1.Text + ' is a ' + days[DayOfWeek(ADate)];
    end;
    另外注意Edit1.Text中的输入格式,比如2001-11-11是合法的
      

  2.   

    ThisNow: TDateTime  iWeek := DayOfWeek(ThisNow);
      

  3.   

    DayOfTheWeek
    Returns the day of the week represented by a TDateTime value.UnitDateUtilsCategorydate/time routinesfunction DayOfTheWeek(const AValue: TDateTime): Word;DescriptionCall DayOfTheWeek to obtain the day of the week represented by a specified TDateTime value. DayOfTheWeek returns a value between 1 and 7, where 1 indicates Monday and 7 indicates Sunday.
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);var
      ADate: TDateTime;
    begin
      ADate := StrToDate(Edit1.Text);
      edit1.text:=inttostr(DayOfWeek(ADate)-1);
    end;
    另外注意Edit1.Text中的输入格式,比如2001-11-11是合法的,
    显示0 为星期天 1为星期一 2为星期二 …… 6为星期六 
    呵呵,偶有个万年历的程序,有阴历和阳历的显示
    要请发MESSAGE给我!
      

  5.   

    This example uses an edit box and a button on a form. When the user enters a date in the edit box in the format associated with the current locale (for example MM/DD/YY format in the US), the string entered is converted to a TDateTime value. This value is used to indicate the day of the week the date represents.procedure TForm1.Button1Click(Sender: TObject);var
      ADate: TDateTime;
      days: array[1..7] of string;
    begin
      days[1] := 'Sunday';
      days[2] := 'Monday';
      days[3] := 'Tuesday';
      days[4] := 'Wednesday';
      days[5] := 'Thursday';
      days[6] := 'Friday';
      days[7] := 'Saturday';
      ADate := StrToDate(Edit1.Text);
      ShowMessage(Edit1.Text + ' is a ' + days[DayOfWeek(ADate)];
    end;
      

  6.   

    Unit
    DateUtilsWeekOfTheMonth()
    function WeekOfTheMonth(const AValue: TDateTime)
    Call WeekOfTheMonth to obtain the week of the month represented by a specified TDateTime value. WeekOfTheMonth returns a value between 1 and 6.
      

  7.   

    dayofweek(now)2: 'Sunday';
    3   'Monday';
    4   'Tuesday';
    5   'Wednesday';
    6   'Thursday';
    7 'Friday';
    1  'Saturday';
      

  8.   

    case dayofweek(now) of 
      1: Edit1.text:='星期天';
      2:Edit1.text:='星期一';
      3:Edit1.text:='星期二';
      4:Edit1.text:='星期三';
      5:Edit1.text:='星期四';
      6:Edit1.text:='星期五';
      7:Edit1.text:='星期六';
    end;