Stores time not exceeding 24 hours. This type has the following constructors:

new TTime(): TTime;
new TTime(duration:  TDuration): TTime; 
new TTime(hours: number, minutes: number, seconds:  number, milliseconds: number): TTime; 

This type is immutable, so mutation methods return the updated value without changing the original one.

const time = new TTime(3, 15, 0, 0);
const newTime =  time.add(2, 15, 0, 0); 
newTime.after(time); // true 

Hierarchy

  • TTime

Properties

Readonly hours

hours: number

Number of hours.

Example:

const time = new TTime(3, 15, 0, 0);
const hours =  time.hours; 

Readonly milliseconds

milliseconds: number

Number of milliseconds.

Example:

const time = new TTime(3, 15, 0, 0);
const  milliseconds = time.milliseconds; 

Readonly minutes

minutes: number

Number of minutes.

Example:

const time = new TTime(3, 15, 0, 0);
const minutes  = time.minutes; 

Readonly seconds

seconds: number

Number of seconds.

Example:

const time = new TTime(3, 15, 0, 0);
const seconds  = time.seconds; 

Methods

add

  • Add time.

    Example:

    const time = new TTime(3, 15, 0, 0);
    const  duration = new Duration(100, 'millisecond'); 
    const newTime = time. add(duration); 
    

    If you set hours to more than 24, the system will subtract 24 , and the new time will be calculated starting from midnight.

    Parameters

    Returns TTime

after

  • Checks whether the specified time is later than another.

    Example:

    const startTime = new TTime(3, 15, 0, 0);
    const  endTime = new TTime(5, 30, 0, 0); 
    const after = startTime.after(endTime); //  false 
    

    Parameters

    Returns boolean

afterOrEqual

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

    Example:

    const startTime = new TTime(3, 15, 0, 0);
    const  endTime = new TTime(5, 30, 0, 0); 
    const before = startTime. afterOrEqual(endTime); // false 
    

    Parameters

    Returns boolean

asDatetime

  • Conversion to date and time.

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

    const time = new TTime(3, 15, 0, 0);
    const date =  new TDate(2021, 1, 20); 
    const datetime = time.asDatetime(date); 
    

    Parameters

    Returns TDatetime

before

  • Checks whether the specified time is earlier than another.

    Example:

    const startTime = new TTime(3, 15, 0, 0);
    const  endTime = new TTime(5, 30, 0, 0); 
    const before = startTime.before(endTime); //  true 
    

    Parameters

    Returns boolean

beforeOrEqual

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

    Example:

    const startTime = new TTime(3, 15, 0, 0);
    const  endTime = new TTime(5, 30, 0, 0); 
    const before = startTime. beforeOrEqual(endTime); // true 
    

    Parameters

    Returns boolean

equal

  • Checks whether two time objects have the same value.

    Example:

    const startTime = new TTime(3, 15, 0, 0);
    const  endTime = new TTime(5, 30, 0, 0); 
    const equal = startTime.equal(endTime); //  false 
    

    Parameters

    Returns boolean

format

  • format(format?: undefined | string): string
  • Coverts the time to the required format.

    The default format is HH:mm:ss. Use the following options to format time:

    • HH is for hours in the 24-hour time format.
    • hh is for hours in the 12-hour time format.
    • mm is for minutes.
    • ss is for seconds.
    • SSS is for milliseconds. Example:
      const time = new TTime(13,  15, 0, 0);
      const formatTime = time.format('hh mm'); // 1pm 15 
      

    Parameters

    • Optional format: undefined | string

    Returns string