Date & Time

TDateTime type and timing methods.


TDateTime.Create

function TDateTime.Create(AYear, AMonth, ADay, AHour, AMinute, ASecond, AMillisecond: Integer): TDateTime; static;

TDateTime.Create

function TDateTime.Create(AYear, AMonth, ADay: Integer): TDateTime; static;

Creates just the date part.


TDateTime.Create

function TDateTime.Create(AHour, AMin, ASecond, AMillisecond: Integer): TDateTime; static;

Creates just the time part.


TDateTime.CreateFromUnix

function TDateTime.CreateFromUnix(UnixTime: Int64): TDateTime; static;

TDateTime.CreateFromISO

function TDateTime.CreateFromISO(Value: String): TDateTime; static;

Create from ISO 8601 string YYYYMMDDThhmmss and YYYY-MM-DD hh:mm:ss format

Examples:

  • 2022-08-30T13:45:38+0000

  • 2022-08-30T13:45:38

  • 20220830 134538


TDateTime.ToUnix

function TDateTime.ToUnix(IsUTC: Boolean = True): Int64;

Convert to unix time. IsUTC determines if Self is already UTC otherwise it will need to be converted.


TDateTime.ToISO

function TDateTime.ToISO(IsUTC: Boolean = True): String;

Convert to ISO 8601 string. IsUTC determines if Self is already UTC otherwise it will need to be converted.


TDateTime.ToString

function TDateTime.ToString(Fmt: String = 'c'): String;

Convert to a human like string. If fmt is unspecified c is used which will produce YYYY-MM-DD hh:mm:ss

  y 	   = Year last 2 digits
  yy 	   = Year last 2 digits
  yyyy 	 = Year as 4 digits
  m 	   = Month number no-leading 0
  mm 	   = Month number as 2 digits
  mmm 	 = Month using ShortDayNames (Jan)
  mmmm 	 = Month using LongDayNames (January)
  d 	   = Day number no-leading 0
  dd 	   = Day number as 2 digits
  ddd    = Day using ShortDayNames (Sun)
  dddd 	 = Day using LongDayNames  (Sunday)
  ddddd  = Day in ShortDateFormat
  dddddd = Day in LongDateFormat

  c 	= Use ShortDateFormat + LongTimeFormat
  h 	= Hour number no-leading 0
  hh 	= Hour number as 2 digits
  n	  = Minute number no-leading 0
  nn 	= Minute number as 2 digits
  s 	= Second number no-leading 0
  ss 	= Second number as 2 digits
  z	  = Milli-sec number no-leading 0s
  zzz = Milli-sec number as 3 digits
  t 	= Use ShortTimeFormat
  tt 	= Use LongTimeFormat

TDateTime.AddYears

function TDateTime.AddYears(Amount: Integer = 1): TDateTime;

TDateTime.AddMonths

function TDateTime.AddMonths(Amount: Integer = 1): TDateTime;

TDateTime.AddDays

function TDateTime.AddDays(Amount: Integer = 1): TDateTime;

TDateTime.AddHours

function TDateTime.AddHours(Amount: Int64 = 1): TDateTime;

TDateTime.AddMinutes

function TDateTime.AddMinutes(Amount: Int64 = 1): TDateTime;

TDateTime.AddSeconds

function TDateTime.AddSeconds(Amount: Int64 = 1): TDateTime;

TDateTime.AddMilliseconds

function TDateTime.AddMilliseconds(Amount: Int64 = 1): TDateTime;

TDateTime.YearsBetween

function TDateTime.YearsBetween(Other: TDateTime): Integer;

TDateTime.MonthsBetween

function TDateTime.MonthsBetween(Other: TDateTime): Integer;

TDateTime.WeeksBetween

function TDateTime.WeeksBetween(Other: TDateTime): Integer;

TDateTime.DaysBetween

function TDateTime.DaysBetween(Other: TDateTime): Integer;

TDateTime.HoursBetween

function TDateTime.HoursBetween(Other: TDateTime): Int64;

TDateTime.MinutesBetween

function TDateTime.MinutesBetween(Other: TDateTime): Int64;

TDateTime.SecondsBetween

function TDateTime.SecondsBetween(Other: TDateTime): Int64;

TDateTime.MilliSecondsBetween

function TDateTime.MilliSecondsBetween(Other: TDateTime): Int64;

TDateTime.Date

property TDateTime.Date: TDateTime
property TDateTime.Date(NewValue: TDateTime)

Read or write just the date part.


TDateTime.Time

property TDateTime.Time: TDateTime
property TDateTime.Time(NewValue: TDateTime)

TDateTime.Year

property TDateTime.Year: Integer
property TDateTime.Year(NewValue: Integer)

TDateTime.Month

property TDateTime.Month: Integer
property TDateTime.Month(NewValue: Integer)

TDateTime.Day

property TDateTime.Day: Integer
property TDateTime.Day(NewValue: Integer)

TDateTime.Hour

property TDateTime.Hour: Integer
property TDateTime.Hour(NewValue: Integer)

TDateTime.Minute

property TDateTime.Minute: Integer
property TDateTime.Minute(NewValue: Integer)

TDateTime.Second

property TDateTime.Second: Integer
property TDateTime.Second(NewValue: Integer)

TDateTime.Millisecond

property TDateTime.Millisecond: Integer
property TDateTime.Millisecond(NewValue: Integer)

Now

function Now: TDateTime;

NowUTC

function NowUTC: TDateTime;

UnixTime

function UnixTime: Int64;

LocalTimeOffset

function LocalTimeOffset: Integer;

Returns the local timezone offset in minutes. This is the difference between UTC time and local time.


PreciseSleep

procedure PreciseSleep(Milliseconds: UInt32);

MillisecondsToTime

function MillisecondsToTime(Time: UInt64; out Days, Hours, Mins, Secs: Integer): Integer;

MillisecondsToTime

function MillisecondsToTime(Time: UInt64; out Years, Months, Weeks, Days, Hours, Mins, Secs: Integer): Integer;

PerformanceTimer

function PerformanceTimer: Double;

FormatMilliseconds

function FormatMilliseconds(Time: Double; Format: String): String;

FormatMilliseconds

function FormatMilliseconds(Time: Double; TimeSymbols: Boolean = False): String;