这些是用于日期和时间计算的函数
{*******************************************************}
{ Date/time 实用程序单元 }
{*******************************************************}
{ 下面的单位是符合ISO 8601标准的。
这意味着这个单位把星期一定为星期的第一天 (5.2.3).
另外,iso8601规定了以下 "一年中的第一个日历周包括了那一年的第一个星期四" (3.17).
换句话说,第一个星期是第一个有四个或更多天的星期。
有关ISO 8601的更多信息,请参阅:http://www.iso.ch/markete/8601.pdf
最受ISO 8601影响的函数在接口部分被标记为这样。
用“iso8601x”标记的函数不能被iso8601直接覆盖,但是它们的功能是对标准的逻辑扩展。
本单元中的一些函数,概念或常量提供者是Jeroen W. Pluimers(http://www.all-im.com)、
Glenn Crouch、Rune Moberg 和 Ray Lischner (http://www.tempest-sw.com).
儒略日期和修正儒略日期函数代码基于NASA的SOHO站点
(http://sohowww.nascom.nasa.gov/solarsoft/gen/idl/time)
他们将基础算法归功于Fliegel和Van Flandern(1968)
Van Flandern在1992年,重印在天文年历的解释增刊上。
在美国海军天文台时间服务网站(http://tycho.usno.navy.mil/mjd.html)
上详细讨论了儒略日期和修正儒略日期
更多信息可以在 (http://www.treasure-troves.com/astro)上找到。
请注意,Delphi RTL日期/时间系统使用了"Proleptic 格林尼治日历"。
也就是说,the Delphi RTL假定格林尼治日历(即公历)一直有效地回到1/1/0001。
这个日历系统的定义可以在:
http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar
因此,RTL并没有解释从儒略历到格林尼治日历的转换所导致的失去的天数。
在16、17、18世纪,甚至更晚的时候,世界经历了不同的时期。
(例如,俄罗斯直到1918年才采用格林尼治日历)
更多关于这个转换,以及由此导致的缺失的日期,可以在维基百科上找到:
http://en.wikipedia.org/wiki/Gregorian_calendar
还应该注意的是,“儒略日期”和“儒略历”之间没有联系。
}
unit System.DateUtils;
interface
{$HPPEMIT LEGACYHPP}
uses
System.SysUtils, System.Types, System.TimeSpan;
{ 简单的修剪函数 }
function DateOf(const AValue: TDateTime): TDateTime; inline;
function TimeOf(const AValue: TDateTime): TDateTime; inline;
{ 混杂函数 }
function IsInLeapYear(const AValue: TDateTime): Boolean;
function IsPM(const AValue: TDateTime): Boolean; inline;
function IsAM(const AValue: TDateTime): Boolean;
function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;
function IsValidTime(const AHour, AMinute, ASecond, AMilliSecond: Word): Boolean;
function IsValidDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
AMilliSecond: Word): Boolean; inline;
function IsValidDateDay(const AYear, ADayOfYear: Word): Boolean;
function IsValidDateWeek(const AYear, AWeekOfYear, {ISO 8601}
ADayOfWeek: Word): Boolean;
function IsValidDateMonthWeek(const AYear, AMonth, AWeekOfMonth, {ISO 8601x}
ADayOfWeek: Word): Boolean;
function WeeksInYear(const AValue: TDateTime): Word; inline; {ISO 8601}
function WeeksInAYear(const AYear: Word): Word; {ISO 8601}
function DaysInYear(const AValue: TDateTime): Word; inline;
function DaysInAYear(const AYear: Word): Word; inline;
function DaysInMonth(const AValue: TDateTime): Word;
function DaysInAMonth(const AYear, AMonth: Word): Word;
function Today: TDateTime;
function Yesterday: TDateTime;
function Tomorrow: TDateTime;
function IsToday(const AValue: TDateTime): Boolean;
function IsSameDay(const AValue, ABasis: TDateTime): Boolean;
{ Pick-a-field 函数 }
function YearOf(const AValue: TDateTime): Word;
function MonthOf(const AValue: TDateTime): Word;
function WeekOf(const AValue: TDateTime): Word; {ISO 8601}
function DayOf(const AValue: TDateTime): Word;
function HourOf(const AValue: TDateTime): Word;
function MinuteOf(const AValue: TDateTime): Word;
function SecondOf(const AValue: TDateTime): Word;
function MilliSecondOf(const AValue: TDateTime): Word;
{ Start/End 函数 }
function StartOfTheYear(const AValue: TDateTime): TDateTime;
function EndOfTheYear(const AValue: TDateTime): TDateTime;
function StartOfAYear(const AYear: Word): TDateTime;
function EndOfAYear(const AYear: Word): TDateTime;
function StartOfTheMonth(const AValue: TDateTime): TDateTime;
function EndOfTheMonth(const AValue: TDateTime): TDateTime;
function StartOfAMonth(const AYear, AMonth: Word): TDateTime;
function EndOfAMonth(const AYear, AMonth: Word): TDateTime;
function StartOfTheWeek(const AValue: TDateTime): TDateTime; {ISO 8601}
function EndOfTheWeek(const AValue: TDateTime): TDateTime; {ISO 8601}
function StartOfAWeek(const AYear, AWeekOfYear: Word; {ISO 8601}
const ADayOfWeek: Word = 1): TDateTime;
function EndOfAWeek(const AYear, AWeekOfYear: Word; {ISO 8601}
const ADayOfWeek: Word = 7): TDateTime;
function StartOfTheDay(const AValue: TDateTime): TDateTime; inline;
function EndOfTheDay(const AValue: TDateTime): TDateTime;
function StartOfADay(const AYear, AMonth, ADay: Word): TDateTime; overload;
function EndOfADay(const AYear, AMonth, ADay: Word): TDateTime; overload;
function StartOfADay(const AYear, ADayOfYear: Word): TDateTime; overload;
function EndOfADay(const AYear, ADayOfYear: Word): TDateTime; overload;
{ This of that functions }
function MonthOfTheYear(const AValue: TDateTime): Word; inline;
function WeekOfTheYear(const AValue: TDateTime): Word; overload; {ISO 8601}
function WeekOfTheYear(const AValue: TDateTime; {ISO 8601}
var AYear: Word): Word; overload;
function DayOfTheYear(const AValue: TDateTime): Word;
function HourOfTheYear(const AValue: TDateTime): Word;
function MinuteOfTheYear(const AValue: TDateTime): Cardinal;
function SecondOfTheYear(const AValue: TDateTime): Cardinal;
function MilliSecondOfTheYear(const AValue: TDateTime): Int64;
function WeekOfTheMonth(const AValue: TDateTime): Word; overload; {ISO 8601x}
function WeekOfTheMonth(const AValue: TDateTime; var AYear, {ISO 8601x}
AMonth: Word): Word; overload;
function DayOfTheMonth(const AValue: TDateTime): Word; inline;
function HourOfTheMonth(const AValue: TDateTime): Word;
function MinuteOfTheMonth(const AValue: TDateTime): Word;
function SecondOfTheMonth(const AValue: TDateTime): Cardinal;
function MilliSecondOfTheMonth(const AValue: TDateTime): Cardinal;
function DayOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function HourOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function MinuteOfTheWeek(const AValue: TDateTime): Word; {ISO 8601}
function SecondOfTheWeek(const AValue: TDateTime): Cardinal; {ISO 8601}
function MilliSecondOfTheWeek(const AValue: TDateTime): Cardinal; {ISO 8601}
function HourOfTheDay(const AValue: TDateTime): Word; inline;
function MinuteOfTheDay(const AValue: TDateTime): Word;
function SecondOfTheDay(const AValue: TDateTime): Cardinal;
function MilliSecondOfTheDay(const AValue: TDateTime): Cardinal;
function MinuteOfTheHour(const AValue: TDateTime): Word; inline;
function SecondOfTheHour(const AValue: TDateTime): Word;
function MilliSecondOfTheHour(const AValue: TDateTime): Cardinal;
function SecondOfTheMinute(const AValue: TDateTime): Word; inline;
function MilliSecondOfTheMinute(const AValue: TDateTime): Cardinal;
function MilliSecondOfTheSecond(const AValue: TDateTime): Word; inline;
{ 范围检查函数 }
function WithinPastYears(const ANow, AThen: TDateTime;
const AYears: Integer): Boolean; inline;
function WithinPastMonths(const ANow, AThen: TDateTime;
const AMonths: Integer): Boolean; inline;
function WithinPastWeeks(const ANow, AThen: TDateTime;
const AWeeks: Integer): Boolean; inline;
function WithinPastDays(const ANow, AThen: TDateTime;
const ADays: Integer): Boolean; inline;
function WithinPastHours(const ANow, AThen: TDateTime;
const AHours: Int64): Boolean; inline;
function WithinPastMinutes(const ANow, AThen: TDateTime;
const AMinutes: Int64): Boolean; inline;
function WithinPastSeconds(const ANow, AThen: TDateTime;
const ASeconds: Int64): Boolean; inline;
function WithinPastMilliSeconds(const ANow, AThen: TDateTime;
const AMilliSeconds: Int64): Boolean; inline;
{ 范围查询函数 }
function YearsBetween(const ANow, AThen: TDateTime): Integer;
function MonthsBetween(const ANow, AThen: TDateTime): Integer;
function WeeksBetween(const ANow, AThen: TDateTime): Integer;
function DaysBetween(const ANow, AThen: TDateTime): Integer;
function HoursBetween(const ANow, AThen: TDateTime): Int64;
function MinutesBetween(const ANow, AThen: TDateTime): Int64;
function SecondsBetween(const ANow, AThen: TDateTime): Int64;
function MilliSecondsBetween(const ANow, AThen: TDateTime): Int64;
{ InRange 函数 }
function DateTimeInRange(ADateTime: TDateTime; AStartDateTime, AEndDateTime: TDateTime; aInclusive: Boolean = True): Boolean;
function DateInRange(ADate: TDate; AStartDate, AEndDate: TDate; AInclusive: Boolean = True): Boolean;
function TimeInRange(ATime: TTime; AStartTime, AEndTime: TTime; AInclusive: Boolean = True): Boolean;
{ 范围涵盖函数 }
{ YearSpan和MonthSpan 接近,不是很精确,但是非常接近 }
function YearSpan(const ANow, AThen: TDateTime): Double;
function MonthSpan(const ANow, AThen: TDateTime): Double;
function WeekSpan(const ANow, AThen: TDateTime): Double;
function DaySpan(const ANow, AThen: TDateTime): Double;
function HourSpan(const ANow, AThen: TDateTime): Double;
function MinuteSpan(const ANow, AThen: TDateTime): Double;
function SecondSpan(const ANow, AThen: TDateTime): Double;
function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
{ 递增/递减datetime字段 }
function IncYear(const AValue: TDateTime;
const ANumberOfYears: Integer = 1): TDateTime; inline;
// IncMonth函数在SysUtils中
function IncWeek(const AValue: TDateTime;
const ANumberOfWeeks: Integer = 1): TDateTime; inline;
function IncDay(const AValue: TDateTime;
const ANumberOfDays: Integer = 1): TDateTime; inline;
function IncHour(const AValue: TDateTime;
const ANumberOfHours: Int64 = 1): TDateTime; inline;
function IncMinute(const AValue: TDateTime;
const ANumberOfMinutes: Int64 = 1): TDateTime; inline;
function IncSecond(const AValue: TDateTime;
const ANumberOfSeconds: Int64 = 1): TDateTime; inline;
function IncMilliSecond(const AValue: TDateTime;
const ANumberOfMilliSeconds: Int64 = 1): TDateTime;
{ 统一的编码/解码函数,可以同时处理所有的datetime字段 }
function EncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
AMilliSecond: Word): TDateTime;
procedure DecodeDateTime(const AValue: TDateTime; out AYear, AMonth, ADay,
AHour, AMinute, ASecond, AMilliSecond: Word);
{ 编码/解码函数,每年的工作周数和每周的工作天数 }
function EncodeDateWeek(const AYear, AWeekOfYear: Word; {ISO 8601}
const ADayOfWeek: Word = 1): TDateTime;
procedure DecodeDateWeek(const AValue: TDateTime; out AYear, {ISO 8601}
AWeekOfYear, ADayOfWeek: Word);
{ 编码/解码函数,每年的工作天数 }
function EncodeDateDay(const AYear, ADayOfYear: Word): TDateTime;
procedure DecodeDateDay(const AValue: TDateTime; out AYear, ADayOfYear: Word);
{ 编码/解码函数,每月的工作周数 }
function EncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, {ISO 8601x}
ADayOfWeek: Word): TDateTime;
procedure DecodeDateMonthWeek(const AValue: TDateTime; {ISO 8601x}
out AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);
{ 下面的函数与上面的函数相似,
只不过它不会在失败时产生异常,而是返回false}
function TryEncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
AMilliSecond: Word; out AValue: TDateTime): Boolean;
function TryEncodeDateWeek(const AYear, AWeekOfYear: Word; {ISO 8601}
out AValue: TDateTime; const ADayOfWeek: Word = 1): Boolean;
function TryEncodeDateDay(const AYear, ADayOfYear: Word;
out AValue: TDateTime): Boolean;
function TryEncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, {ISO 8601x}
ADayOfWeek: Word; var AValue: TDateTime): Boolean;
{用于datetime字段的Recode函数 }
function RecodeYear(const AValue: TDateTime; const AYear: Word): TDateTime;
function RecodeMonth(const AValue: TDateTime; const AMonth: Word): TDateTime;
function RecodeDay(const AValue: TDateTime; const ADay: Word): TDateTime;
function RecodeHour(const AValue: TDateTime; const AHour: Word): TDateTime;
function RecodeMinute(const AValue: TDateTime; const AMinute: Word): TDateTime;
function RecodeSecond(const AValue: TDateTime; const ASecond: Word): TDateTime;
function RecodeMilliSecond(const AValue: TDateTime;
const AMilliSecond: Word): TDateTime;
function RecodeDate(const AValue: TDateTime; const AYear, AMonth,
ADay: Word): TDateTime;
function RecodeTime(const AValue: TDateTime; const AHour, AMinute, ASecond,
AMilliSecond: Word): TDateTime;
function RecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay,
AHour, AMinute, ASecond, AMilliSecond: Word): TDateTime;
{ 下面的函数与上面的函数类似,只不过它不会在失败时产生异常,而是返回false
}
function TryRecodeDateTime(const AValue: TDateTime; const AYear, AMonth, ADay,
AHour, AMinute, ASecond, AMilliSecond: Word; out AResult: TDateTime): Boolean;
{ Fuzzy comparison }
function CompareDateTime(const A, B: TDateTime): TValueRelationship;
function SameDateTime(const A, B: TDateTime): Boolean;
function CompareDate(const A, B: TDateTime): TValueRelationship;
function SameDate(const A, B: TDateTime): Boolean;
function CompareTime(const A, B: TDateTime): TValueRelationship;
function SameTime(const A, B: TDateTime): Boolean;
{ 对于给定的日期,这些函数会告诉你一个月(或一年)的周的哪一天。
如果是周四,,他们会告诉你这个月(或年)的第一个,第二个,星期四。
记住,即使是今年的第一个星期四,也不意味着它是一年中第一周。
有关更多信息,请参阅上面的ISO 8601。 }
function NthDayOfWeek(const AValue: TDateTime): Word;
procedure DecodeDayOfWeekInMonth(const AValue: TDateTime; out AYear, AMonth,
ANthDayOfWeek, ADayOfWeek: Word);
function EncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek,
ADayOfWeek: Word): TDateTime;
function TryEncodeDayOfWeekInMonth(const AYear, AMonth, ANthDayOfWeek,
ADayOfWeek: Word; out AValue: TDateTime): Boolean;
{ 错误报告 }
procedure InvalidDateTimeError(const AYear, AMonth, ADay, AHour, AMinute,
ASecond, AMilliSecond: Word; const ABaseDate: TDateTime = 0);
procedure InvalidDateWeekError(const AYear, AWeekOfYear, ADayOfWeek: Word);
procedure InvalidDateDayError(const AYear, ADayOfYear: Word);
procedure InvalidDateMonthWeekError(const AYear, AMonth, AWeekOfMonth,
ADayOfWeek: Word);
procedure InvalidDayOfWeekInMonthError(const AYear, AMonth, ANthDayOfWeek,
ADayOfWeek: Word);
{ 儒略历和修正儒略历 日期转换支持 }
{ 请注意,并非所有的儒略历(或修正儒略历)都可编码为TDateTime }
function DateTimeToJulianDate(const AValue: TDateTime): Double;
function JulianDateToDateTime(const AValue: Double): TDateTime;
function TryJulianDateToDateTime(const AValue: Double;
out ADateTime: TDateTime): Boolean;
function DateTimeToModifiedJulianDate(const AValue: TDateTime): Double;
function ModifiedJulianDateToDateTime(const AValue: Double): TDateTime;
function TryModifiedJulianDateToDateTime(const AValue: Double;
out ADateTime: TDateTime): Boolean;
{ Unix日期转换支持 }
function DateTimeToUnix(const AValue: TDateTime; AInputIsUTC: Boolean = True): Int64;
function UnixToDateTime(const AValue: Int64; AReturnUTC: Boolean = True): TDateTime;
{ 本单元使用的常量 }
const
DaysPerWeek = 7;
WeeksPerFortnight = 2;
MonthsPerYear = 12;
YearsPerDecade = 10;
YearsPerCentury = 100;
YearsPerMillennium = 1000;
DayMonday = 1;
DayTuesday = 2;
DayWednesday = 3;
DayThursday = 4;
DayFriday = 5;
DaySaturday = 6;
DaySunday = 7;
MonthJanuary = 1;
MonthFebruary = 2;
MonthMarch = 3;
MonthApril = 4;
MonthMay = 5;
MonthJune = 6;
MonthJuly = 7;
MonthAugust = 8;
MonthSeptember = 9;
MonthOctober = 10;
MonthNovember = 11;
MonthDecember = 12;
OneHour = 1 / HoursPerDay;
{$HPPEMIT OPENNAMESPACE}
{$EXTERNALSYM OneHour}
{$HPPEMIT 'extern const System::Extended OneHour /*= 4.166667E-02*/;'}
OneMinute = 1 / MinsPerDay;
{$EXTERNALSYM OneMinute}
{$HPPEMIT 'extern const System::Extended OneMinute /*= 6.944444E-04*/;'}
OneSecond = 1 / SecsPerDay;
{$EXTERNALSYM OneSecond}
{$HPPEMIT 'extern const System::Extended OneSecond /*= 1.157407E-05*/;'}
OneMillisecond = 1 / MSecsPerDay;
{$EXTERNALSYM OneMillisecond}
{$HPPEMIT 'extern const System::Extended OneMillisecond /*= 1.157407E-08*/;'}
EpochAsJulianDate = 2415018.5;
{$EXTERNALSYM EpochAsJulianDate}
{$HPPEMIT 'extern const System::Extended EpochAsJulianDate /*= 2.415018E+06*/;'}
{$HPPEMIT CLOSENAMESPACE}
EpochAsUnixDate = -2209161600;
{ 这是每年的实际天数,但你需要知道这是否是闰年}
DaysPerYear: array [Boolean] of Word = (365, 366);
{ 用于您不想管理的datetime字段的RecodeDate、recode和RecodeDateTime }
{ }
RecodeLeaveFieldAsIs = High(Word);
{ 本单元使用的全局变量 }
var
{ 平均4年跨度 }
ApproxDaysPerMonth: Double = 30.4375;
ApproxDaysPerYear: Double = 365.25;
{ 以上是一个正常的4年平均的每个月/年的平均天数。 }
{ 我们使用这些近似值,因为它们在接下来的一个世纪里更准确。 }
{ 在那之后你可能想要转换到这400年的近似值... }
{ }
{ ApproxDaysPerMonth = 30.436875 }
{ ApproxDaysPerYear = 365.2425 }
type
{ 本单元中使用的异常类型,用于指示给定的本地时间位于无效周期内。
(通常是在DST的时间转换过程中丢失的小时). }
ELocalTimeInvalid = class(Exception);
EDateTimeException = class(Exception);
{ 指定日期/时间值的类型 }
TLocalTimeType = (
{ 当DST规则无效时,识别一个日期/时间值 }
lttStandard,
{ 当DST规则生效时,识别一个日期/时间值 }
lttDaylight,
{ 识别位于模糊区间的日期/时间值 (例子, 重复的小时) }
lttAmbiguous,
{ 识别位于无效区间中的日期/时间值 (漏掉的小时) }
lttInvalid
);
{ 使用TTimeZone来访问一组方法, 这些方法可用于在本地时间
(就像现在的时区用户所看到的那样)和通用时间之间进行转换。 }
TTimeZone = class abstract
private
{包含“本地”时区。 :在单元initialization部分实例化 }
class var FLocal: TTimeZone;
{ 在initialization期间调用。 初始化缓存(空)和本地时区 }
class constructor Create;
{ 在initialization期间调用。 销毁内部缓存和包含的时区 (包括本地的那个) }
class destructor Destroy;
{ 返回当前时区的缩写名称 }
function GetAbbreviationForNow: string; inline;
{ 返回当前时区的显示名称 }
function GetDisplayNameForNow: string; inline;
{ 为给定的本地时间计算UTC偏移量。UTC偏移量表示时间的长度,
这应该从给定的本地时间中减去,以获得国际标准时间。 }
function GetUtcOffsetInSeconds(const ADateTime: TDateTime; const ForceDaylight: Boolean): Int64;
{ 返回当前时区的UTC偏移量 }
function GetCurrentUtcOffset: TTimeSpan; inline;
protected
{ 在派生类中覆盖,以提供关于本地时间的偏移信息。}
procedure DoGetOffsetsAndType(
const ADateTime: TDateTime; out AOffset, ADstSave: Int64; out AType: TLocalTimeType); virtual; abstract;
{ 在派生类中重写,以在给定的本地时间提供一个TZ名称。 }
function DoGetDisplayName(const ADateTime: TDateTime; const ForceDaylight: Boolean): string; virtual; abstract;
{ 重载返回时区ID。}
function DoGetID: string; virtual; abstract;
public
{ 为给定的本地时间计算UTC偏移量。UTC偏移量表示时间的长度,
这应该从给定的本地时间中减去,以获得国际标准时间。
ForceDaylight指定了模糊时间的处理方式。}
function GetUtcOffset(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): TTimeSpan; inline;
{ 将给定的本地时间转换为国际标准时间。
ForceDaylight指定了模糊时间的处理方式。 }
function ToUniversalTime(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): TDateTime; inline;
{ 将一个给定的国际标准时间转换为本地时间。 }
function ToLocalTime(const ADateTime: TDateTime): TDateTime;
{ 根据给定的日期/时间,返回时区的全名(如果可能的话是本地化的) }
function GetDisplayName(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): string;
{ 返回一个简短的名称,可以用来定位与UTC时间相关的本地时间。
非本地化的,总是指定的,并且有形式: GMT[+|-HH[:MM]]. }
function GetAbbreviation(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): string;
{ 在这个时区返回给定日期/时间的类型。 }
function GetLocalTimeType(const ADateTime: TDateTime): TLocalTimeType; inline;
{检查给定的本地日期/时间是否位于DST周期之外。
ForceDaylight指定了时间的处理方式。 }
function IsStandardTime(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): Boolean;
{ 检查给定的本地日期/时间是否无效(位于不确定的小时(s)内) }
function IsInvalidTime(const ADateTime: TDateTime): Boolean; inline;
{ 检查给定的本地日期/时间是否为模糊(位于重复的小时(s)中) }
function IsAmbiguousTime(const ADateTime: TDateTime): Boolean; inline;
{ 检查给定的本地日期/时间是否位于DST周期内。
ForceDaylight指定了时间的处理方式。}
function IsDaylightTime(const ADateTime: TDateTime; const ForceDaylight: Boolean = False): Boolean;
{ 返回时区标识字符串。 }
property ID: string read DoGetID;
{ 指定这个时区的显示名称(如果可能的话本地化)。 }
property DisplayName: string read GetDisplayNameForNow;
{ 当前时区的缩写。非本地化的,总是指定的,并且有表单:GMT[+|-HH[:MM]]。}
property Abbreviation: string read GetAbbreviationForNow;
{ 指定时区当前的UTC偏移量。 }
property UtcOffset: TTimeSpan read GetCurrentUtcOffset;
{ 指定本地时区。
使用此属性获得一个TTimeZone实例,该实例标识当前用户的时区。 }
class property Local: TTimeZone read FLocal;
end;
/// <summary>
/// 将一个ISO8601编码的日期/时间字符串转换为TDateTime。如果AReturnUTC 是 false,结果是在当地时间。
/// </summary>
/// <example>
/// <para> "2013-10-18T20:36:22.966Z" </para>
/// <para> 这是UTC时间20:36(祖鲁)。如果本地时区是MEST(UTC+2),那么产生的时间将是22:36。</para>
/// </example>
function ISO8601ToDate(const AISODate: string; AReturnUTC: Boolean = True): TDateTime;
/// <summary> 尝试将ISO8601编码的日期/时间字符串转换为TDateTime。 </summary>
/// <param name ="AISODate"> 一个ISO8601字符串, 举例来说, "2013-10-18T20:36:22.966Z" </param>
/// <param name ="Value"> 输出TDateTime值的参数 </param>
/// <param name = "AReturnUTC"> UTC时间(祖鲁语) </param>
/// <returns> 布尔表明成功 </returns>
function TryISO8601ToDate(const AISODate: string; out Value: TDateTime; AReturnUTC: Boolean = True): Boolean;
/// <summary> 将TDateTime值转换为ISO8601格式。 </summary>
/// <param name="ADate"> 一个TDateTime值 </param>
/// <param name="AInputIsUTC">
/// 如果AInputIsUTC =true, 然后得到的ISO8601字符串将显示与ADate相同的时间。</param>
/// <returns> ADate的ISO8601表示。得到的ISO字符串将在UTC时间,也就是说,将有一个Z(祖鲁)的后缀
/// 如果AInputIsUTC = true, 那么,ADate的时间部分将不会被修改。 </returns>
function DateToISO8601(const ADate: TDateTime; AInputIsUTC: Boolean = True): string;