DateTime
Overview
Represents a date and time of day.
Use case
You can use DateTime class when you need to define a instant in time, for example:
var Date := new Sugar.DateTime(1939, 9, 1);
var FormatedDate := Date.ToString("World War 2 started at {d} {MMMM} {yyyy}", "en-US");
writeLn(FormatedDate);
Output:
World War 2 started at 1 September 1939
Formating
DateTime class can be formated by using ToString
method overrides. Format string can holds regular characters and format specifiers, specifiers must be enclosed by braces. Currently following format specifiers available:
Format Specifier | Description | Example |
---|---|---|
yy | Formats year with two digits. | 01/01/2001 -> 01 |
yyyy | Formats year with four digits. | 01/01/2001 -> 2001 |
M | Formats month with one digit. | 01/01/2001 -> 1 |
MM | Formats month with two digits. | 01/01/2001 -> 01 |
MMM | Formats month with short name. | 01/01/2001 -> Jan |
MMMM | Formats month with full name. | 01/01/2001 -> January |
d | Formats day with one digit. | 01/01/2001 -> 1 |
dd | Formats day with two digits. | 01/01/2001 -> 01 |
ddd | Formats day with short name. | 01/01/2001 -> Mon |
dddd | Formats day with full name. | 01/01/2001 -> Monday |
h | Formats hour with one digit (1 - 12) | 01/01/2001 16:48:52 -> 4 |
hh | Formats hour with two digits (1 - 12) | 01/01/2001 16:48:52 -> 04 |
H | Formats hour with one digit (0 - 23) | 01/01/2001 07:48:52 -> 7 |
HH | Formats hour with two digits (0 - 23) | 01/01/2001 16:48:52 -> 16 |
m | Formats minutes with one digit | 01/01/2001 16:09:52 -> 9 |
mm | Formats minutes with two digits | 01/01/2001 16:09:52 -> 09 |
s | Formats seconds with one digit | 01/01/2001 16:09:04 -> 4 |
ss | Formats seconds with two digits | 01/01/2001 16:09:04 -> 04 |
a | AM/PM designator. | 01/01/2001 16:09:04 -> PM |
Please note that all string information for days, month and AM/PM is related to a current platform.
Location
constructor
Creates a new instance of the class with current date and time.
constructor
DateTime()
init()
DateTime()
Sub New()
Creates a new instance of the class with specified date information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
Creates a new instance of the class with specified date and time information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32; anHour: Int32; aMinute: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32, _ anHour: Int32, _ aMinute: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32, anHour As Int32, aMinute As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
- anHour: The hour.
- aMinute: The minute.
Creates a new instance of the class with specified date and time information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32; anHour: Int32; aMinute: Int32; aSecond: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute, Int32 aSecond)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32, _ anHour: Int32, _ aMinute: Int32, _ aSecond: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute, Int32 aSecond)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32, anHour As Int32, aMinute As Int32, aSecond As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
- anHour: The hour.
- aMinute: The minute.
- aSecond: The second.
constructor (Int64)
constructor(aTicks: Int64)
DateTime(Int64 aTicks)
init(_ aTicks: Int64)
DateTime(Int64 aTicks)
Sub New(aTicks As Int64)
Parameters:
- aTicks:
AddDays mapped
Adds the specified number of days to the current date.
method AddDays(Value: Int32): DateTime
DateTime AddDays(Int32 Value)
func AddDays(_ Value: Int32) -> DateTime
DateTime AddDays(Int32 Value)
Function AddDays(Value As Int32) As DateTime
Parameters:
- Value: The number of days.
AddHours mapped
Adds the specified number of hours to the current time.
method AddHours(Value: Int32): DateTime
DateTime AddHours(Int32 Value)
func AddHours(_ Value: Int32) -> DateTime
DateTime AddHours(Int32 Value)
Function AddHours(Value As Int32) As DateTime
Parameters:
- Value: The number of hours.
AddMinutes mapped
Adds the specified number of minutes to the current time.
method AddMinutes(Value: Int32): DateTime
DateTime AddMinutes(Int32 Value)
func AddMinutes(_ Value: Int32) -> DateTime
DateTime AddMinutes(Int32 Value)
Function AddMinutes(Value As Int32) As DateTime
Parameters:
- Value: The number of minutes.
AddMonths mapped
Adds the specified number of months to the current date.
method AddMonths(Value: Int32): DateTime
DateTime AddMonths(Int32 Value)
func AddMonths(_ Value: Int32) -> DateTime
DateTime AddMonths(Int32 Value)
Function AddMonths(Value As Int32) As DateTime
Parameters:
- Value: The number of months.
AddSeconds mapped
Adds the specified number of seconds to the current time.
method AddSeconds(Value: Int32): DateTime
DateTime AddSeconds(Int32 Value)
func AddSeconds(_ Value: Int32) -> DateTime
DateTime AddSeconds(Int32 Value)
Function AddSeconds(Value As Int32) As DateTime
Parameters:
- Value: The number of seconds.
AddYears mapped
Adds the specified number of years to the current date.
method AddYears(Value: Int32): DateTime
DateTime AddYears(Int32 Value)
func AddYears(_ Value: Int32) -> DateTime
DateTime AddYears(Int32 Value)
Function AddYears(Value As Int32) As DateTime
Parameters:
- Value: The number of years.
CompareTo mapped
Compares the current instance to a specified value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified value.
method CompareTo(Value: DateTime): Int32
Int32 CompareTo(DateTime Value)
func CompareTo(_ Value: DateTime) -> Int32
Int32 CompareTo(DateTime Value)
Function CompareTo(Value As DateTime) As Int32
Parameters:
- Value: DateTime to compare.
Date
Gets date part of the current instance.
property Date: DateTime read;
DateTime Date { get; }
var Date: DateTime { get{} }
DateTime Date { __get; }
ReadOnly Property Date() As DateTime
Day
Gets days of the current instance.
property Day: Int32 read;
Int32 Day { get; }
var Day: Int32 { get{} }
Int32 Day { __get; }
ReadOnly Property Day() As Int32
DayOfWeek
property DayOfWeek: Int32 read;
Int32 DayOfWeek { get; }
var DayOfWeek: Int32 { get{} }
Int32 DayOfWeek { __get; }
ReadOnly Property DayOfWeek() As Int32
Hour
Gets hours of the current instance.
property Hour: Int32 read;
Int32 Hour { get; }
var Hour: Int32 { get{} }
Int32 Hour { __get; }
ReadOnly Property Hour() As Int32
Minute
Gets minutes of the current instance.
property Minute: Int32 read;
Int32 Minute { get; }
var Minute: Int32 { get{} }
Int32 Minute { __get; }
ReadOnly Property Minute() As Int32
Month
Gets months of the current instance.
property Month: Int32 read;
Int32 Month { get; }
var Month: Int32 { get{} }
Int32 Month { __get; }
ReadOnly Property Month() As Int32
Second
Gets seconds of the current instance.
property Second: Int32 read;
Int32 Second { get; }
var Second: Int32 { get{} }
Int32 Second { __get; }
ReadOnly Property Second() As Int32
Ticks
property Ticks: Int64 read;
Int64 Ticks { get; }
var Ticks: Int64 { get{} }
Int64 Ticks { __get; }
ReadOnly Property Ticks() As Int64
TicksSince1970
const TicksSince1970: Int64
const Int64 TicksSince1970
static let TicksSince1970: Int64
static final Int64 TicksSince1970
Const TicksSince1970 As Int64
class method TimeSince(aOtherDateTime: DateTime): TimeSpan
static TimeSpan TimeSince(DateTime aOtherDateTime)
static func TimeSince(_ aOtherDateTime: DateTime) -> TimeSpan
static TimeSpan TimeSince(DateTime aOtherDateTime)
Shared Function TimeSince(aOtherDateTime As DateTime) As TimeSpan
Parameters:
- aOtherDateTime:
TimeSince
property TimeSince: TimeSpan read;
TimeSpan TimeSince { get; }
var TimeSince: TimeSpan { get{} }
TimeSpan TimeSince { __get; }
ReadOnly Property TimeSince() As TimeSpan
Today
Gets a new instance of the DateTime class initialized with current date.
class property Today: DateTime read;
class DateTime Today { get; }
static var Today: DateTime { get{} }
class DateTime Today { __get; }
Shared ReadOnly Property Today() As DateTime
ToLongPrettyDateString mapped
method ToLongPrettyDateString(aTimeZone: TimeZone): String
String ToLongPrettyDateString(TimeZone aTimeZone)
func ToLongPrettyDateString(_ aTimeZone: TimeZone) -> String
String ToLongPrettyDateString(TimeZone aTimeZone)
Function ToLongPrettyDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortDateString mapped
method ToShortDateString(aTimeZone: TimeZone): String
String ToShortDateString(TimeZone aTimeZone)
func ToShortDateString(_ aTimeZone: TimeZone) -> String
String ToShortDateString(TimeZone aTimeZone)
Function ToShortDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortPrettyDateString mapped
method ToShortPrettyDateString(aTimeZone: TimeZone): String
String ToShortPrettyDateString(TimeZone aTimeZone)
func ToShortPrettyDateString(_ aTimeZone: TimeZone) -> String
String ToShortPrettyDateString(TimeZone aTimeZone)
Function ToShortPrettyDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortTimeString mapped
method ToShortTimeString(aTimeZone: TimeZone): String
String ToShortTimeString(TimeZone aTimeZone)
func ToShortTimeString(_ aTimeZone: TimeZone) -> String
String ToShortTimeString(TimeZone aTimeZone)
Function ToShortTimeString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToString mapped
Converts current date and time value with a default format. Default format is - {dd}/{MM}/{yyyy} {hh}:{mm}:{ss}
method ToString: String
String ToString()
func ToString() -> String
String ToString()
Function ToString() As String
method ToString(aTimeZone: TimeZone): String
String ToString(TimeZone aTimeZone)
func ToString(_ aTimeZone: TimeZone) -> String
String ToString(TimeZone aTimeZone)
Function ToString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
method ToString(Format: String; aTimeZone: TimeZone): String
String ToString(String Format, TimeZone aTimeZone)
func ToString(_ Format: String, _ aTimeZone: TimeZone) -> String
String ToString(String Format, TimeZone aTimeZone)
Function ToString(Format As String, aTimeZone As TimeZone) As String
Parameters:
- Format:
- aTimeZone:
method ToString(Format: String; Culture: String; aTimeZone: TimeZone): String
String ToString(String Format, String Culture, TimeZone aTimeZone)
func ToString(_ Format: String, _ Culture: String, _ aTimeZone: TimeZone) -> String
String ToString(String Format, String Culture, TimeZone aTimeZone)
Function ToString(Format As String, Culture As String, aTimeZone As TimeZone) As String
Parameters:
- Format:
- Culture:
- aTimeZone:
UtcNow
class property UtcNow: DateTime read;
class DateTime UtcNow { get; }
static var UtcNow: DateTime { get{} }
class DateTime UtcNow { __get; }
Shared ReadOnly Property UtcNow() As DateTime
Year
Gets years of the current instance.
property Year: Int32 read;
Int32 Year { get; }
var Year: Int32 { get{} }
Int32 Year { __get; }
ReadOnly Property Year() As Int32
TicksSince1970
const TicksSince1970: Int64
const Int64 TicksSince1970
static let TicksSince1970: Int64
static final Int64 TicksSince1970
Const TicksSince1970 As Int64
Date
Gets date part of the current instance.
property Date: DateTime read;
DateTime Date { get; }
var Date: DateTime { get{} }
DateTime Date { __get; }
ReadOnly Property Date() As DateTime
Day
Gets days of the current instance.
property Day: Int32 read;
Int32 Day { get; }
var Day: Int32 { get{} }
Int32 Day { __get; }
ReadOnly Property Day() As Int32
DayOfWeek
property DayOfWeek: Int32 read;
Int32 DayOfWeek { get; }
var DayOfWeek: Int32 { get{} }
Int32 DayOfWeek { __get; }
ReadOnly Property DayOfWeek() As Int32
Hour
Gets hours of the current instance.
property Hour: Int32 read;
Int32 Hour { get; }
var Hour: Int32 { get{} }
Int32 Hour { __get; }
ReadOnly Property Hour() As Int32
Minute
Gets minutes of the current instance.
property Minute: Int32 read;
Int32 Minute { get; }
var Minute: Int32 { get{} }
Int32 Minute { __get; }
ReadOnly Property Minute() As Int32
Month
Gets months of the current instance.
property Month: Int32 read;
Int32 Month { get; }
var Month: Int32 { get{} }
Int32 Month { __get; }
ReadOnly Property Month() As Int32
Second
Gets seconds of the current instance.
property Second: Int32 read;
Int32 Second { get; }
var Second: Int32 { get{} }
Int32 Second { __get; }
ReadOnly Property Second() As Int32
Ticks
property Ticks: Int64 read;
Int64 Ticks { get; }
var Ticks: Int64 { get{} }
Int64 Ticks { __get; }
ReadOnly Property Ticks() As Int64
TimeSince
property TimeSince: TimeSpan read;
TimeSpan TimeSince { get; }
var TimeSince: TimeSpan { get{} }
TimeSpan TimeSince { __get; }
ReadOnly Property TimeSince() As TimeSpan
Today
Gets a new instance of the DateTime class initialized with current date.
class property Today: DateTime read;
class DateTime Today { get; }
static var Today: DateTime { get{} }
class DateTime Today { __get; }
Shared ReadOnly Property Today() As DateTime
UtcNow
class property UtcNow: DateTime read;
class DateTime UtcNow { get; }
static var UtcNow: DateTime { get{} }
class DateTime UtcNow { __get; }
Shared ReadOnly Property UtcNow() As DateTime
Year
Gets years of the current instance.
property Year: Int32 read;
Int32 Year { get; }
var Year: Int32 { get{} }
Int32 Year { __get; }
ReadOnly Property Year() As Int32
class method TimeSince(aOtherDateTime: DateTime): TimeSpan
static TimeSpan TimeSince(DateTime aOtherDateTime)
static func TimeSince(_ aOtherDateTime: DateTime) -> TimeSpan
static TimeSpan TimeSince(DateTime aOtherDateTime)
Shared Function TimeSince(aOtherDateTime As DateTime) As TimeSpan
Parameters:
- aOtherDateTime:
constructor
Creates a new instance of the class with current date and time.
constructor
DateTime()
init()
DateTime()
Sub New()
Creates a new instance of the class with specified date information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
Creates a new instance of the class with specified date and time information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32; anHour: Int32; aMinute: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32, _ anHour: Int32, _ aMinute: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32, anHour As Int32, aMinute As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
- anHour: The hour.
- aMinute: The minute.
Creates a new instance of the class with specified date and time information.
constructor(aYear: Int32; aMonth: Int32; aDay: Int32; anHour: Int32; aMinute: Int32; aSecond: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute, Int32 aSecond)
init(_ aYear: Int32, _ aMonth: Int32, _ aDay: Int32, _ anHour: Int32, _ aMinute: Int32, _ aSecond: Int32)
DateTime(Int32 aYear, Int32 aMonth, Int32 aDay, Int32 anHour, Int32 aMinute, Int32 aSecond)
Sub New(aYear As Int32, aMonth As Int32, aDay As Int32, anHour As Int32, aMinute As Int32, aSecond As Int32)
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
- anHour: The hour.
- aMinute: The minute.
- aSecond: The second.
constructor (Int64)
constructor(aTicks: Int64)
DateTime(Int64 aTicks)
init(_ aTicks: Int64)
DateTime(Int64 aTicks)
Sub New(aTicks As Int64)
Parameters:
- aTicks:
AddDays mapped
Adds the specified number of days to the current date.
method AddDays(Value: Int32): DateTime
DateTime AddDays(Int32 Value)
func AddDays(_ Value: Int32) -> DateTime
DateTime AddDays(Int32 Value)
Function AddDays(Value As Int32) As DateTime
Parameters:
- Value: The number of days.
AddHours mapped
Adds the specified number of hours to the current time.
method AddHours(Value: Int32): DateTime
DateTime AddHours(Int32 Value)
func AddHours(_ Value: Int32) -> DateTime
DateTime AddHours(Int32 Value)
Function AddHours(Value As Int32) As DateTime
Parameters:
- Value: The number of hours.
AddMinutes mapped
Adds the specified number of minutes to the current time.
method AddMinutes(Value: Int32): DateTime
DateTime AddMinutes(Int32 Value)
func AddMinutes(_ Value: Int32) -> DateTime
DateTime AddMinutes(Int32 Value)
Function AddMinutes(Value As Int32) As DateTime
Parameters:
- Value: The number of minutes.
AddMonths mapped
Adds the specified number of months to the current date.
method AddMonths(Value: Int32): DateTime
DateTime AddMonths(Int32 Value)
func AddMonths(_ Value: Int32) -> DateTime
DateTime AddMonths(Int32 Value)
Function AddMonths(Value As Int32) As DateTime
Parameters:
- Value: The number of months.
AddSeconds mapped
Adds the specified number of seconds to the current time.
method AddSeconds(Value: Int32): DateTime
DateTime AddSeconds(Int32 Value)
func AddSeconds(_ Value: Int32) -> DateTime
DateTime AddSeconds(Int32 Value)
Function AddSeconds(Value As Int32) As DateTime
Parameters:
- Value: The number of seconds.
AddYears mapped
Adds the specified number of years to the current date.
method AddYears(Value: Int32): DateTime
DateTime AddYears(Int32 Value)
func AddYears(_ Value: Int32) -> DateTime
DateTime AddYears(Int32 Value)
Function AddYears(Value As Int32) As DateTime
Parameters:
- Value: The number of years.
CompareTo mapped
Compares the current instance to a specified value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified value.
method CompareTo(Value: DateTime): Int32
Int32 CompareTo(DateTime Value)
func CompareTo(_ Value: DateTime) -> Int32
Int32 CompareTo(DateTime Value)
Function CompareTo(Value As DateTime) As Int32
Parameters:
- Value: DateTime to compare.
ToLongPrettyDateString mapped
method ToLongPrettyDateString(aTimeZone: TimeZone): String
String ToLongPrettyDateString(TimeZone aTimeZone)
func ToLongPrettyDateString(_ aTimeZone: TimeZone) -> String
String ToLongPrettyDateString(TimeZone aTimeZone)
Function ToLongPrettyDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortDateString mapped
method ToShortDateString(aTimeZone: TimeZone): String
String ToShortDateString(TimeZone aTimeZone)
func ToShortDateString(_ aTimeZone: TimeZone) -> String
String ToShortDateString(TimeZone aTimeZone)
Function ToShortDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortPrettyDateString mapped
method ToShortPrettyDateString(aTimeZone: TimeZone): String
String ToShortPrettyDateString(TimeZone aTimeZone)
func ToShortPrettyDateString(_ aTimeZone: TimeZone) -> String
String ToShortPrettyDateString(TimeZone aTimeZone)
Function ToShortPrettyDateString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToShortTimeString mapped
method ToShortTimeString(aTimeZone: TimeZone): String
String ToShortTimeString(TimeZone aTimeZone)
func ToShortTimeString(_ aTimeZone: TimeZone) -> String
String ToShortTimeString(TimeZone aTimeZone)
Function ToShortTimeString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
ToString mapped
Converts current date and time value with a default format. Default format is - {dd}/{MM}/{yyyy} {hh}:{mm}:{ss}
method ToString: String
String ToString()
func ToString() -> String
String ToString()
Function ToString() As String
method ToString(aTimeZone: TimeZone): String
String ToString(TimeZone aTimeZone)
func ToString(_ aTimeZone: TimeZone) -> String
String ToString(TimeZone aTimeZone)
Function ToString(aTimeZone As TimeZone) As String
Parameters:
- aTimeZone:
method ToString(Format: String; aTimeZone: TimeZone): String
String ToString(String Format, TimeZone aTimeZone)
func ToString(_ Format: String, _ aTimeZone: TimeZone) -> String
String ToString(String Format, TimeZone aTimeZone)
Function ToString(Format As String, aTimeZone As TimeZone) As String
Parameters:
- Format:
- aTimeZone:
method ToString(Format: String; Culture: String; aTimeZone: TimeZone): String
String ToString(String Format, String Culture, TimeZone aTimeZone)
func ToString(_ Format: String, _ Culture: String, _ aTimeZone: TimeZone) -> String
String ToString(String Format, String Culture, TimeZone aTimeZone)
Function ToString(Format As String, Culture As String, aTimeZone As TimeZone) As String
Parameters:
- Format:
- Culture:
- aTimeZone: