Ballerina API Documentation

Functions of ballerina.lang.time package

function addDuration(Time timeData, int years, int months, int days, int hours, int minutes, int seconds, int milliSeconds) (Time )

Add specified durations to the given time value.

Parameters:

Parameter NameData TypeDescription
timeDataTimeyear : The year representation
yearsintyear : The year representation
monthsintyear : The year representation
daysintyear : The year representation
hoursintyear : The year representation
minutesintyear : The year representation
secondsintyear : The year representation
milliSecondsintyear : The year representation

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing time and zone information after the addition.

function createTime(int year, int month, int date, int hour, int minute, int second, int milliSecond, string zoneId) (Time )

Returns the the date and time components and timezone.

Parameters:

Parameter NameData TypeDescription
yearintyear : The year representation
monthintyear : The year representation
dateintyear : The year representation
hourintyear : The year representation
minuteintyear : The year representation
secondintyear : The year representation
milliSecondintyear : The year representation
zoneIdstringyear : The year representation

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing time and zone information.

function currentTime() (Time )

Returns the current time value with the system default timezone.

Parameters:

Parameter NameData TypeDescription

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing the time and zone information.

function day(Time time) (int )

Returns the date representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the date representation

Return Parameters:

Return VariableData TypeDescription
intint: The day-of-month, from 1 to 31.

function format(Time time, string format) (string )

Returns formatted string representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct for which needs to get the string representation
formatstringtime : The time struct for which needs to get the string representation

Return Parameters:

Return VariableData TypeDescription
stringstring: The formatted string of the given time.

function getDate(Time time) (int , int , int )

Returns the date representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the date representation

Return Parameters:

Return VariableData TypeDescription
intint: The year representation.
intint: The year representation.
intint: The year representation.

function getTime(Time time) (int , int , int , int )

Returns the time representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the time representation

Return Parameters:

Return VariableData TypeDescription
intint: The hour-of-day, from 0 to 23.
intint: The hour-of-day, from 0 to 23.
intint: The hour-of-day, from 0 to 23.
intint: The hour-of-day, from 0 to 23.

function hour(Time time) (int )

Returns the hour representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the hour representation

Return Parameters:

Return VariableData TypeDescription
intint: The hour-of-day, from 0 to 23.

function milliSecond(Time time) (int )

Returns the millisecond representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the millisecond representation

Return Parameters:

Return VariableData TypeDescription
intint: The milli-of-second, from 0 to 999.

function minute(Time time) (int )

Returns the minute representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the minute representation

Return Parameters:

Return VariableData TypeDescription
intint: The minute-of-hour to represent, from 0 to 59.

function month(Time time) (int )

Returns the month representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the month representation

Return Parameters:

Return VariableData TypeDescription
intint: The month-of-year, from 1 (January) to 12 (December).

function parse(string data, string format) (Time )

Returns the time for the given string representation based on the given format string.

Parameters:

Parameter NameData TypeDescription
datastringdata : The time text to parse
formatstringdata : The time text to parse

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing time and zone information.

function second(Time time) (int )

Returns the second representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the second representation

Return Parameters:

Return VariableData TypeDescription
intint: The second-of-minute, from 0 to 59.

function subtractDuration(Time timeData, int years, int months, int days, int hours, int minutes, int seconds, int milliSeconds) (Time )

Subtract specified durations from the given time value.

Parameters:

Parameter NameData TypeDescription
timeDataTimeyear : The year representation
yearsintyear : The year representation
monthsintyear : The year representation
daysintyear : The year representation
hoursintyear : The year representation
minutesintyear : The year representation
secondsintyear : The year representation
milliSecondsintyear : The year representation

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing time and zone information after the subtraction.

function toString(Time time) (string )

Returns ISO 8601 string representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct for which needs to get the string representation

Return Parameters:

Return VariableData TypeDescription
stringstring: The ISO 8601 formatted string of the given time.

function toTimezone(Time timeData, string zoneId) (Time )

Change the timezone of the given time.

Parameters:

Parameter NameData TypeDescription
timeDataTimetime : The time struct which needs to change the timezone information
zoneIdstringtime : The time struct which needs to change the timezone information

Return Parameters:

Return VariableData TypeDescription
Timeballerina.lang.time:Time: Time struct containing time and zone information after the conversion.

function weekday(Time time) (string )

Returns the weekday representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the weekday representation

Return Parameters:

Return VariableData TypeDescription
stringstring: The weekday representation from SUNDAY to SATURDAY.

function year(Time time) (int )

Returns the year representation of the given time.

Parameters:

Parameter NameData TypeDescription
timeTimetime : The time struct which needs to get the year representation

Return Parameters:

Return VariableData TypeDescription
intint: The year representation.


Structs of ballerina.lang.time package

struct Time

Fields:

Field NameData TypeDescription
timeintTime value as milliseconds since epoch.
zoneTimezoneThe time zone of the time.

struct Timezone

Fields:

Field NameData TypeDescription
zoneIdstringZone short ID or offset string.
zoneOffsetintThe offset in seconds.


Menu

  • Functions
    • addDuration(Time timeData, int years, int months, int days, int hours, int minutes, int seconds, int milliSeconds) (Time )
    • createTime(int year, int month, int date, int hour, int minute, int second, int milliSecond, string zoneId) (Time )
    • currentTime() (Time )
    • day(Time time) (int )
    • format(Time time, string format) (string )
    • getDate(Time time) (int , int , int )
    • getTime(Time time) (int , int , int , int )
    • hour(Time time) (int )
    • milliSecond(Time time) (int )
    • minute(Time time) (int )
    • month(Time time) (int )
    • parse(string data, string format) (Time )
    • second(Time time) (int )
    • subtractDuration(Time timeData, int years, int months, int days, int hours, int minutes, int seconds, int milliSeconds) (Time )
    • toString(Time time) (string )
    • toTimezone(Time timeData, string zoneId) (Time )
    • weekday(Time time) (string )
    • year(Time time) (int )
  • Structs
    • Time
    • Timezone

Copyright 2017 Ballerina API Documentation