ballerina.time package
public struct Time
Ballerina Time struct represents a particular time with its associated timezone.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
time | int | Time value as milliseconds since epoch. | |
zone | Timezone | The time zone of the time. |
-
< Time > addDuration ( int years , int months , int days , int hours , int minutes , int seconds , int milliSeconds ) ( Time )
Add specified durations to the given time value.
Parameter Name Data Type Description years int The year representation months int The month-of-year to represent, from 1 (January) to 12 (December) days int The day-of-month to represent, from 1 to 31 hours int The hour-of-day to represent, from 0 to 23 minutes int The minute-of-hour to represent, from 0 to 59 seconds int The second-of-minute to represent, from 0 to 59 milliSeconds int The milli-of-second to represent, from 0 to 999 Return Variable Data Type Description Time Time struct containing time and zone information after the addition. -
< Time > day ( ) ( int )
Returns the date representation of the given time.
Return Variable Data Type Description int The day-of-month, from 1 to 31. -
< Time > format ( string format ) ( string )
Returns formatted string representation of the given time.
Parameter Name Data Type Description format string The format which is used to format the given text Return Variable Data Type Description string The formatted string of the given time. -
< Time > getDate ( ) ( int , int , int )
Returns the date representation of the given time.
Return Variable Data Type Description int The year representation. int The month-of-year, from 1 (January) to 12 (December). int The day-of-month, from 1 to 31. -
< Time > getTime ( ) ( int , int , int , int )
Returns the time representation of the given time.
Return Variable Data Type Description int The hour-of-day, from 0 to 23. int The minute-of-hour to represent, from 0 to 59. int The second-of-minute, from 0 to 59. int The milli-of-second, from 0 to 999. -
< Time > hour ( ) ( int )
Returns the hour representation of the given time.
Return Variable Data Type Description int The hour-of-day, from 0 to 23. -
< Time > milliSecond ( ) ( int )
Returns the millisecond representation of the given time.
Return Variable Data Type Description int The milli-of-second, from 0 to 999. -
< Time > minute ( ) ( int )
Returns the minute representation of the given time.
Return Variable Data Type Description int The minute-of-hour to represent, from 0 to 59. -
< Time > month ( ) ( int )
Returns the month representation of the given time.
Return Variable Data Type Description int The month-of-year, from 1 (January) to 12 (December). -
< Time > second ( ) ( int )
Returns the second representation of the given time.
Return Variable Data Type Description int The second-of-minute, from 0 to 59. -
< Time > subtractDuration ( int years , int months , int days , int hours , int minutes , int seconds , int milliSeconds ) ( Time )
Subtract specified durations from the given time value.
Parameter Name Data Type Description years int The year representation months int The month-of-year to represent, from 1 (January) to 12 (December) days int The day-of-month to represent, from 1 to 31 hours int The hour-of-day to represent, from 0 to 23 minutes int The minute-of-hour to represent, from 0 to 59 seconds int The second-of-minute to represent, from 0 to 59 milliSeconds int The milli-of-second to represent, from 0 to 999 Return Variable Data Type Description Time Time struct containing time and zone information after the subtraction. -
< Time > toString ( ) ( string )
Returns ISO 8601 string representation of the given time.
Return Variable Data Type Description string The ISO 8601 formatted string of the given time. -
< Time > toTimezone ( string zoneId ) ( Time )
Change the timezone of the given time.
Parameter Name Data Type Description zoneId string The new timezone id Return Variable Data Type Description Time Time struct containing time and zone information after the conversion. -
< Time > weekday ( ) ( string )
Returns the weekday representation of the given time.
Return Variable Data Type Description string The weekday representation from SUNDAY to SATURDAY. -
< Time > year ( ) ( int )
Returns the year representation of the given time.
Return Variable Data Type Description int The year representation.
public struct Timezone
Ballerina Timezone struct represents the timezone information associated with a particular time.
Field Name | Data Type | Description | Default Value |
---|---|---|---|
zoneId | string | Zone short ID or offset string. | |
zoneOffset | int | The offset in seconds. |
public function createTime ( int year , int month , int date , int hour , int minute , int second , int milliSecond , string zoneId ) ( Time )
Returns the Time struct correspoding to the given time components and timezone.
Parameter Name | Data Type | Description |
---|---|---|
year | int | The year representation |
month | int | The month-of-year to represent, from 1 (January) to 12 (December) |
date | int | The day-of-month to represent, from 1 to 31 |
hour | int | The hour-of-day to represent, from 0 to 23 |
minute | int | The minute-of-hour to represent, from 0 to 59 |
second | int | The second-of-minute to represent, from 0 to 59 |
milliSecond | int | The milli-of-second to represent, from 0 to 999 |
zoneId | string | The zone id of the required timezone.If empty the system local timezone will be used |
Return Variable | Data Type | Description |
---|---|---|
Time | Time struct containing time and zone information. |
public function currentTime ( ) ( Time )
Returns the current time value with the system default timezone.
Return Variable | Data Type | Description |
---|---|---|
Time | Time struct containing the time and zone information. |
public function parse ( string data , string format ) ( Time )
Returns the time for the given string representation based on the given format string.
Parameter Name | Data Type | Description |
---|---|---|
data | string | The time text to parse |
format | string | The format which is used to parse the given text |
Return Variable | Data Type | Description |
---|---|---|
Time | Time struct containing time and zone information. |