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 Name | Data Type | Description |
---|---|---|
timeData | Time | year : The year representation |
years | int | year : The year representation |
months | int | year : The year representation |
days | int | year : The year representation |
hours | int | year : The year representation |
minutes | int | year : The year representation |
seconds | int | year : The year representation |
milliSeconds | int | year : The year representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|---|---|
year | int | year : The year representation |
month | int | year : The year representation |
date | int | year : The year representation |
hour | int | year : The year representation |
minute | int | year : The year representation |
second | int | year : The year representation |
milliSecond | int | year : The year representation |
zoneId | string | year : The year representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the date representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | 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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct for which needs to get the string representation |
format | string | time : The time struct for which needs to get the string representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | The formatted string of the given time. |
function getDate(Time time) (int , int , int )
Returns the date representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the date representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The year representation. | |
int | The year representation. | |
int | The year representation. |
function getTime(Time time) (int , int , int , int )
Returns the time representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the time representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The hour-of-day, from 0 to 23. | |
int | The hour-of-day, from 0 to 23. | |
int | The hour-of-day, from 0 to 23. | |
int | The hour-of-day, from 0 to 23. |
function hour(Time time) (int )
Returns the hour representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the hour representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The hour-of-day, from 0 to 23. |
function milliSecond(Time time) (int )
Returns the millisecond representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the millisecond representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The milli-of-second, from 0 to 999. |
function minute(Time time) (int )
Returns the minute representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the minute representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | 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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the month representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | 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 Name | Data Type | Description |
---|---|---|
data | string | data : The time text to parse |
format | string | data : The time text to parse |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the second representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | 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 Name | Data Type | Description |
---|---|---|
timeData | Time | year : The year representation |
years | int | year : The year representation |
months | int | year : The year representation |
days | int | year : The year representation |
hours | int | year : The year representation |
minutes | int | year : The year representation |
seconds | int | year : The year representation |
milliSeconds | int | year : The year representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct for which needs to get the string representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | 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 Name | Data Type | Description |
---|---|---|
timeData | Time | time : The time struct which needs to change the timezone information |
zoneId | string | time : The time struct which needs to change the timezone information |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Time | ballerina.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 Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the weekday representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
string | The weekday representation from SUNDAY to SATURDAY. |
function year(Time time) (int )
Returns the year representation of the given time.
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
time | Time | time : The time struct which needs to get the year representation |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | The year representation. |
Structs of ballerina.lang.time package
struct Time
Fields:
Field Name | Data Type | Description |
---|---|---|
time | int | Time value as milliseconds since epoch. |
zone | Timezone | The time zone of the time. |
struct Timezone
Fields:
Field Name | Data Type | Description |
---|---|---|
zoneId | string | Zone short ID or offset string. |
zoneOffset | int | The offset in seconds. |