DateTimeToSystemTimeConverts a TDateTime value into the Win32 API's TSystemTime type.UnitSysUtilsCategorydate/time routinesprocedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);DescriptionUse DateTimeToSystemTime to convert a TDateTime value into a TSystemTime value to use with an API call. UnitWindowstype PSystemTime = ^TSystemTime; TSystemTime = record wYear: Word; wMonth: Word; wDayOfWeek: Word;//这就是你要的了 wDay: Word; wHour: Word; wMinute: Word; wSecond: Word; wMilliseconds: Word; end;
这个函数DayOfWeek就可以搞定。
用dayoftheweek(星期一为1)或者dayofweek(星期日为1) var theWeek:word; begin theWeek:=dayoftheweek(Date); case theWeek of 6:begin showmessage('星期六'); end; 7:begin showmessage('星期日'); end; end; end;
下面一个简单的例子: 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;
UnitWindowstype
PSystemTime = ^TSystemTime;
TSystemTime = record
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;//这就是你要的了
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
end;
var
theWeek:word;
begin
theWeek:=dayoftheweek(Date);
case theWeek of
6:begin
showmessage('星期六');
end;
7:begin
showmessage('星期日');
end;
end;
end;
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;
还是0..6对应于Sunday到Saturday比较符合习惯。
按下F1然后再查看See also,有更多相关的日期/时间函数/过程。
1: Edit1.text:='星期天';
2:Edit1.text:='星期一';
3:Edit1.text:='星期二';
4:Edit1.text:='星期三';
5:Edit1.text:='星期四';
6:Edit1.text:='星期五';
7:Edit1.text:='星期六';
end;