我随意输入一个日期如2004.3.3,如何得到它是星期几,谢谢

解决方案 »

  1.   

    函数DayofWeek
    范例:
    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;
      

  2.   

    Edit1.Text := FormatDateTime('ddd', Date());
      

  3.   

    Edit1.Text := FormatDateTime('dddd', StrToDate(2004-3-3));
    :b 三个d表示短格式,四个表示长格式,依计算机区域设定而决定
      

  4.   

    DayofWeek,返回0星期日,1星期一,好像是这样,看看
      

  5.   

    上面的这位楼主好象不对
    showmessage(formatdatetime('dddd',strToDate('2004-4-26')));
      

  6.   

    showmessage(formatdatetime('dddd',strToDate('2004-4-26')));我机子上跳出"星期一",怎么不对?
      

  7.   

    DayOfWeekNameDayOfWeekShortName
    StrToDate, DayOfWeek ExampleThis 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;
      

  8.   

    showmessage(formatdatetime('dddd',DateTimePicker1.DateTime));
      

  9.   

    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;
      

  10.   

    var
      week:array[1..7]of string=('星期天','星期一','星期二','星期三','星期四','星期五','星期六');
    begin
      StatusBar1.Panels[2].Text:='  当前日期:'+inttostr(yearof(now))+'年'+inttostr(monthof(now))+'月'+inttostr(dayof(now))+'日'+week[dayofweek(now)];
    end;
      

  11.   

    dayofweek()
    formatdatetime('dddd',date())