The type has the following constructors:

new Datetime(input?:  Date): TDatetime;
new Datetime(value: string, format?: string): TDatetime;  

Examples of how Date/Time objects can be created:

const now = new Datetime();
const time1 = new Datetime('2022-02-24');  
const time2 = new Datetime('24.02.2022', 'DD.MM.YYYY'); 
const time3 = new  Datetime(Date.UTC(2022, 2, 24)); 

If you write the data as a string and don’t specify the format in the constructor, by default the value is checked against the YYYY-MM-DDTHH:mm:ss.SSSZ format. So you can set the value in the following way:

  • 2021-01
  • 2021-01-23
  • 2021-01-21T08:30, etc. This type is immutable, so mutation methods return the updated value
    without changing the original one.
    const now = new  Datetime();
    const yesterday = now.addDate(0, 0, -1); 
    now.after(yesterday)  // true 
    
    If you want all dates to be calculated in the user’s time zone, you need to expressly state this by setting the current time zone:
    // Getting the user we need for calculations 
    const user =  ...; 
    // Setting the time zone for all further calculations in the script  
    System.timezones.current = user.timezone; 
    const today_22_00 = Context.data. datavremya.getDate().asDatetime(new TTime(22, 0, 0, 0)); 
    

Hierarchy

  • TDatetime

Properties

Readonly day

day: number

Day of the month (1-31).

Readonly hours

hours: number

Hours (0-23).

Readonly milliseconds

milliseconds: number

Milliseconds (0-999).

Readonly minutes

minutes: number

Minutes (0-59).

Readonly month

month: number

Month (1-12).

Readonly seconds

seconds: number

Seconds (0-59).

Readonly year

year: number

Year.

Methods

add

  • Add a duration.

    Parameters

    Returns TDatetime

addDate

  • addDate(years: number, month: number, days: number): TDatetime
  • Add days, months, or years.

    Parameters

    • years: number
    • month: number
    • days: number

    Returns TDatetime

after

  • Checks whether the current date is later than date.

    Parameters

    Returns boolean

afterOrEqual

  • Checks whether the current date is the same as or later than date.

    Example:

    const startDatetime = new Datetime();
    const  endDatetime = (new Datetime()).addDate(0, 0, 1); 
    const beforeOrEqual =  startDatetime.afterOrEqual(endDatetime); // false 
    

    Parameters

    Returns boolean

asDate

  • asDate(): Date
  • Converting to the standard Date type.

    Returns Date

before

  • Checks whether the current date is earlier than date.

    Parameters

    Returns boolean

beforeOrEqual

  • Checks whether the current date is the same as or earlier than date.

    Example:

    const startDatetime = new Datetime();
    const  endDatetime = (new Datetime()).addDate(0, 0, 1); 
    const beforeOrEqual =  startDatetime.beforeOrEqual(endDatetime); // true 
    

    Parameters

    Returns boolean

equal

  • Checks whether two objects have the same value.

    Parameters

    Returns boolean

format

  • format(format?: undefined | string): string
  • Converting to a string of a specific format.

    Here the [moment.format() syntax](https://momentjs.com/docs/#/displaying/ format/) is used. Example:

    const datetime = new Datetime();
    datetime.format();                                //  '2022-02-24T09:00:00+02:00' (ISO 8601 standard) 
    datetime.format('dddd, MMMM  Do YYYY, h:mm:ss a'); // 'Thursday, February 24th 2022, 9:00:00 am' 
    datetime .format('ddd, h A');                      // 'Thu, 9AM' 
    datetime.format('[ Today is] dddd');               // 'Today is Thursday' 
    

    Parameters

    • Optional format: undefined | string

    Returns string

getDate

  • Get date.

    Returns the date in the specified time zone or in the current one if the time zone is not specified (by default, the company’s time zone).

    Parameters

    Returns TDate

getTime

  • Get time.

    Returns the time from the start of day in the specified time zone or in the current one, if the time zone is not specified (by default, the company’s time zone).

    Parameters

    Returns TTime

sub

  • Subtraction of dates. Returns a duration.

    Parameters

    Returns TDuration

truncateTime

  • Round up to the start of the day.

    Resets the time to 00:00 and returns the date in the UTC format.

    Returns TDatetime

unix

  • unix(): number
  • Number of seconds that have elapsed since 00:00:00 01.01.1970 UTC.

    Returns number

utc

  • Returns a date and time in UTC.

    Returns TDatetime