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.
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
Creates a new instance of the class with specified date and time information.
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)
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.
Parameters:
- Value: The number of days.
AddHours mapped
Adds the specified number of hours to the current time.
Parameters:
- Value: The number of hours.
AddMinutes mapped
Adds the specified number of minutes to the current time.
Parameters:
- Value: The number of minutes.
AddMonths mapped
Adds the specified number of months to the current date.
Parameters:
- Value: The number of months.
AddSeconds mapped
Adds the specified number of seconds to the current time.
Parameters:
- Value: The number of seconds.
AddYears mapped
Adds the specified number of years to the current date.
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.
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
Dim TicksSince1970 As Int64
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
Parameters:
- aTimeZone:
ToShortDateString mapped
Parameters:
- aTimeZone:
ToShortPrettyDateString mapped
Parameters:
- aTimeZone:
ToShortTimeString mapped
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
Parameters:
- aTimeZone:
Parameters:
- Format:
- aTimeZone:
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.
TicksSince1970
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.
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.
Parameters:
- aYear: The year.
- aMonth: The month.
- aDay: The day.
Creates a new instance of the class with specified date and time information.
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)
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.
Parameters:
- Value: The number of days.
AddHours mapped
Adds the specified number of hours to the current time.
Parameters:
- Value: The number of hours.
AddMinutes mapped
Adds the specified number of minutes to the current time.
Parameters:
- Value: The number of minutes.
AddMonths mapped
Adds the specified number of months to the current date.
Parameters:
- Value: The number of months.
AddSeconds mapped
Adds the specified number of seconds to the current time.
Parameters:
- Value: The number of seconds.
AddYears mapped
Adds the specified number of years to the current date.
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.
Parameters:
- Value: DateTime to compare.
ToLongPrettyDateString mapped
Parameters:
- aTimeZone:
ToShortDateString mapped
Parameters:
- aTimeZone:
ToShortPrettyDateString mapped
Parameters:
- aTimeZone:
ToShortTimeString mapped
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
Parameters:
- aTimeZone:
Parameters:
- Format:
- aTimeZone:
Parameters:
- Format:
- Culture:
- aTimeZone: