$Calendar¶
Provides the default calendar instance with domain-specific calendar rules.
1 | |
Remarks¶
$Calendar is used to obtain the current date and time, perform date and time arithmetic (addition and subtraction), and manage time zone conversions.
$Calendar can be utilized in both client-side and server-side scripts. In server-side scripts, both synchronous and asynchronous methods are supported. However, client-side scripts are restricted to asynchronous methods due to their inherent asynchronous nature.
$Calendar defaults to using the domain calendar rules. For specific calendar implementations, refer to the Calendar.StandardCalendar or Calendar.WeekendCalendar objects.
Server-side example for adding days:
Example¶
1 2 | |
Client-side example for adding days (asynchronous):
Example¶
1 2 | |
Capabilities¶
Presets¶
$Calendar.StandardCalendar: Gets the standard calendar with 7/24 hours.$Calendar.WeekendCalendar: Gets the weekend calendar with 5/24 hours.
Calendar Queries¶
$Calendar.Today: Returns the current date and time in UTC time.$Calendar.GetDateTime: Returns the next valid date and time, according to calendar rules, after adding the given duration to the specified date.$Calendar.GetHoursInDay: Returns the total number of hours in the specified date.$Calendar.GetToday: Returns the current date and time in the specified time zone.
Date Arithmetic¶
$Calendar.Add: Adds a specified number of hours to aDateTimeOffsetvalue and returns the result.$Calendar.AddDays: Adds a specified number of days to aDateTimeOffsetvalue and returns the next valid date and time according to the calendar rules.$Calendar.AddMonths: Adds a specified number of months to aDateTimeOffsetvalue and returns the result.$Calendar.AddTimeSpan: Returns a newDateTimeOffsetby adding a specified duration, considering calendar rules.$Calendar.AddYears: Adds a specified number of years to aDateTimeOffsetvalue and returns the result.$Calendar.Subtract: Subtracts one date-time value from another and returns the difference in hours.
Async Date Arithmetic¶
$Calendar.AddAsync: Adds a specified number of hours to aDateTimeOffsetvalue asynchronously.$Calendar.AddDaysAsync: Adds a specified number of days to aDateTimeOffsetvalue asynchronously.$Calendar.AddMonthsAsync: Adds a specified number of months to aDateTimeOffsetvalue asynchronously.$Calendar.AddTimeSpanAsync: Adds a specified time span to aDateTimeOffsetvalue asynchronously.$Calendar.AddYearsAsync: Adds a specified number of years to aDateTimeOffsetvalue asynchronously.$Calendar.SubtractAsync: Subtracts aDateTimeOffsetvalue from another and returns the difference in hours asynchronously.
Time Zones¶
$Calendar.ChangeTimeZone: Returns a newDateTimeOffsetwith the specified time zone offset.$Calendar.GetTimeZone: Returns the time zone information of the specifiedDateTimeOffsetvalue.
Async Time Zones¶
$Calendar.ChangeTimeZoneAsync: Returns a newDateTimeOffsetwith the specified time zone offset asynchronously.$Calendar.GetTimeZoneAsync: Returns the time zone offset of aDateTimeOffsetvalue asynchronously.
Async Calendar Queries¶
$Calendar.GetDateTimeAsync: Returns the next valid date and time, according to calendar rules, after adding a given duration.$Calendar.GetTodayAsync: Returns the current date in the specified time zone asynchronously.
Creation and Presets¶
$Calendar.GetStandardCalendar: Gets the standard calendar with 7/24 hours (24 hours, 7 days a week).$Calendar.GetWeekendCalendar: Gets the weekend calendar with 5/24 hours (24 hours, 5 days a week).$Calendar.Parse: Parses a calendar rule from an XML string or Xml object and returns aCalendarobject.