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

  • Reference: Sugar
  • Namespace: Sugar
  • Ancestry: ValueType | DateTime

 

constructor

Creates a new instance of the class with current date and time.

 

constructor

 

DateTime()

 

init()

 

DateTime()

constructor (Int32, Int32, Int32)

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)

Parameters:

  • aYear: The year.
  • aMonth: The month.
  • aDay: The day.

constructor (Int32, Int32, Int32, Int32, Int32)

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)

Parameters:

  • aYear: The year.
  • aMonth: The month.
  • aDay: The day.
  • anHour: The hour.
  • aMinute: The minute.

constructor (Int32, Int32, Int32, Int32, Int32, Int32)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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; }

Day

Gets days of the current instance.

 

property Day: Int32 read;

 

Int32 Day { get; }

 

var Day: Int32 { get{} }

 

Int32 Day { __get; }

DayOfWeek

 

property DayOfWeek: Int32 read;

 

Int32 DayOfWeek { get; }

 

var DayOfWeek: Int32 { get{} }

 

Int32 DayOfWeek { __get; }

Hour

Gets hours of the current instance.

 

property Hour: Int32 read;

 

Int32 Hour { get; }

 

var Hour: Int32 { get{} }

 

Int32 Hour { __get; }

Minute

Gets minutes of the current instance.

 

property Minute: Int32 read;

 

Int32 Minute { get; }

 

var Minute: Int32 { get{} }

 

Int32 Minute { __get; }

Month

Gets months of the current instance.

 

property Month: Int32 read;

 

Int32 Month { get; }

 

var Month: Int32 { get{} }

 

Int32 Month { __get; }

Second

Gets seconds of the current instance.

 

property Second: Int32 read;

 

Int32 Second { get; }

 

var Second: Int32 { get{} }

 

Int32 Second { __get; }

Ticks

 

property Ticks: Int64 read;

 

Int64 Ticks { get; }

 

var Ticks: Int64 { get{} }

 

Int64 Ticks { __get; }

TicksSince1970

 

const TicksSince1970: Int64;

 

const Int64 TicksSince1970

 

static let TicksSince1970: Int64

 

static final Int64 TicksSince1970

TimeSince (DateTime): TimeSpan

 

class method TimeSince(aOtherDateTime: DateTime): TimeSpan

 

static TimeSpan TimeSince(DateTime aOtherDateTime)

 

static func TimeSince(_ aOtherDateTime: DateTime) -> TimeSpan

 

static TimeSpan TimeSince(DateTime aOtherDateTime)

Parameters:

  • aOtherDateTime:

TimeSince

 

property TimeSince: TimeSpan read;

 

TimeSpan TimeSince { get; }

 

var TimeSince: TimeSpan { get{} }

 

TimeSpan TimeSince { __get; }

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; }

ToLongPrettyDateString  mapped

 

method ToLongPrettyDateString(aTimeZone: TimeZone): String

 

String ToLongPrettyDateString(TimeZone aTimeZone)

 

func ToLongPrettyDateString(_ aTimeZone: TimeZone) -> String

 

String ToLongPrettyDateString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToShortDateString  mapped

 

method ToShortDateString(aTimeZone: TimeZone): String

 

String ToShortDateString(TimeZone aTimeZone)

 

func ToShortDateString(_ aTimeZone: TimeZone) -> String

 

String ToShortDateString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToShortPrettyDateString  mapped

 

method ToShortPrettyDateString(aTimeZone: TimeZone): String

 

String ToShortPrettyDateString(TimeZone aTimeZone)

 

func ToShortPrettyDateString(_ aTimeZone: TimeZone) -> String

 

String ToShortPrettyDateString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToShortTimeString  mapped

 

method ToShortTimeString(aTimeZone: TimeZone): String

 

String ToShortTimeString(TimeZone aTimeZone)

 

func ToShortTimeString(_ aTimeZone: TimeZone) -> String

 

String ToShortTimeString(TimeZone aTimeZone)

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()

ToString (TimeZone): String  mapped

 

method ToString(aTimeZone: TimeZone): String

 

String ToString(TimeZone aTimeZone)

 

func ToString(_ aTimeZone: TimeZone) -> String

 

String ToString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToString (String, TimeZone): String  mapped

 

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)

Parameters:

  • Format:
  • aTimeZone:

ToString (String, String, TimeZone): String  mapped

 

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)

Parameters:

  • Format:
  • Culture:
  • aTimeZone:

UtcNow

 

class property UtcNow: DateTime read;

 

class DateTime UtcNow { get; }

 

static var UtcNow: DateTime { get{} }

 

class DateTime UtcNow { __get; }

Year

Gets years of the current instance.

 

property Year: Int32 read;

 

Int32 Year { get; }

 

var Year: Int32 { get{} }

 

Int32 Year { __get; }

 

TicksSince1970

 

const TicksSince1970: Int64;

 

const Int64 TicksSince1970

 

static let TicksSince1970: Int64

 

static final Int64 TicksSince1970

 

Date

Gets date part of the current instance.

 

property Date: DateTime read;

 

DateTime Date { get; }

 

var Date: DateTime { get{} }

 

DateTime Date { __get; }

Day

Gets days of the current instance.

 

property Day: Int32 read;

 

Int32 Day { get; }

 

var Day: Int32 { get{} }

 

Int32 Day { __get; }

DayOfWeek

 

property DayOfWeek: Int32 read;

 

Int32 DayOfWeek { get; }

 

var DayOfWeek: Int32 { get{} }

 

Int32 DayOfWeek { __get; }

Hour

Gets hours of the current instance.

 

property Hour: Int32 read;

 

Int32 Hour { get; }

 

var Hour: Int32 { get{} }

 

Int32 Hour { __get; }

Minute

Gets minutes of the current instance.

 

property Minute: Int32 read;

 

Int32 Minute { get; }

 

var Minute: Int32 { get{} }

 

Int32 Minute { __get; }

Month

Gets months of the current instance.

 

property Month: Int32 read;

 

Int32 Month { get; }

 

var Month: Int32 { get{} }

 

Int32 Month { __get; }

Second

Gets seconds of the current instance.

 

property Second: Int32 read;

 

Int32 Second { get; }

 

var Second: Int32 { get{} }

 

Int32 Second { __get; }

Ticks

 

property Ticks: Int64 read;

 

Int64 Ticks { get; }

 

var Ticks: Int64 { get{} }

 

Int64 Ticks { __get; }

TimeSince

 

property TimeSince: TimeSpan read;

 

TimeSpan TimeSince { get; }

 

var TimeSince: TimeSpan { get{} }

 

TimeSpan TimeSince { __get; }

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; }

UtcNow

 

class property UtcNow: DateTime read;

 

class DateTime UtcNow { get; }

 

static var UtcNow: DateTime { get{} }

 

class DateTime UtcNow { __get; }

Year

Gets years of the current instance.

 

property Year: Int32 read;

 

Int32 Year { get; }

 

var Year: Int32 { get{} }

 

Int32 Year { __get; }

 

TimeSince (DateTime): TimeSpan

 

class method TimeSince(aOtherDateTime: DateTime): TimeSpan

 

static TimeSpan TimeSince(DateTime aOtherDateTime)

 

static func TimeSince(_ aOtherDateTime: DateTime) -> TimeSpan

 

static TimeSpan TimeSince(DateTime aOtherDateTime)

Parameters:

  • aOtherDateTime:

 

constructor

Creates a new instance of the class with current date and time.

 

constructor

 

DateTime()

 

init()

 

DateTime()

constructor (Int32, Int32, Int32)

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)

Parameters:

  • aYear: The year.
  • aMonth: The month.
  • aDay: The day.

constructor (Int32, Int32, Int32, Int32, Int32)

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)

Parameters:

  • aYear: The year.
  • aMonth: The month.
  • aDay: The day.
  • anHour: The hour.
  • aMinute: The minute.

constructor (Int32, Int32, Int32, Int32, Int32, Int32)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

Parameters:

  • aTimeZone:

ToShortDateString  mapped

 

method ToShortDateString(aTimeZone: TimeZone): String

 

String ToShortDateString(TimeZone aTimeZone)

 

func ToShortDateString(_ aTimeZone: TimeZone) -> String

 

String ToShortDateString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToShortPrettyDateString  mapped

 

method ToShortPrettyDateString(aTimeZone: TimeZone): String

 

String ToShortPrettyDateString(TimeZone aTimeZone)

 

func ToShortPrettyDateString(_ aTimeZone: TimeZone) -> String

 

String ToShortPrettyDateString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToShortTimeString  mapped

 

method ToShortTimeString(aTimeZone: TimeZone): String

 

String ToShortTimeString(TimeZone aTimeZone)

 

func ToShortTimeString(_ aTimeZone: TimeZone) -> String

 

String ToShortTimeString(TimeZone aTimeZone)

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()

ToString (TimeZone): String  mapped

 

method ToString(aTimeZone: TimeZone): String

 

String ToString(TimeZone aTimeZone)

 

func ToString(_ aTimeZone: TimeZone) -> String

 

String ToString(TimeZone aTimeZone)

Parameters:

  • aTimeZone:

ToString (String, TimeZone): String  mapped

 

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)

Parameters:

  • Format:
  • aTimeZone:

ToString (String, String, TimeZone): String  mapped

 

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)

Parameters:

  • Format:
  • Culture:
  • aTimeZone: