我研究TDateTime函数和过程,但没有找到允许我在相应的年,月,日转换若干天的东西,例如,如果我有天= 0我应该得到结果:
Year: 0
Month: 0
Day: 0
Run Code Online (Sandbox Code Playgroud)
或者我有天= 1,应该有:
Year: 0
Month: 0
Day: 1 // Just 1 day
Run Code Online (Sandbox Code Playgroud)
或者如果我有天= 32:
Year: 0
Month: 1 // January is 31 days
Day: 1 // Day is 1
// Total are 32 days
Run Code Online (Sandbox Code Playgroud)
等等,考虑到2月份是29天而不仅仅是28日.在delphi xe2中,谁可以告诉我它做了什么功能,或者是否需要手动编写?非常感谢.
使用DateUtils中的方法:
procedure daysToDate(days: Integer; out day, month, year: Integer);
var
january1st: TDateTime;
targetDate: TDateTime;
begin
january1st := StartOfTheYear(Now());
targetDate := IncDay(january1st, days);
day := DayOfTheMonth(targetDate) - 1;
month := MonthOfTheYear(targetDate) - 1;
year := YearOf(targetDate) - YearOf(january1st);
end;
Run Code Online (Sandbox Code Playgroud)
此代码假定您计算当前年份的天数.如果您想在不同的年份开始,请january1st := StartOfTheYear(Now());根据需要修改该行.
| 归档时间: |
|
| 查看次数: |
3344 次 |
| 最近记录: |