'How to get a relative date in Ballerina

I want to get a Civil date object relative to 2 days from now. For example, if today is 28th Feb 2022, I want to add 2 days to it.

My ballerina version is

Ballerina 2201.0.1 (Swan Lake)
Language specification 2022R1
Update Tool 1.3.9


Solution 1:[1]

How about something like this? You can use time:utcAddSeconds() function for this purpose.

time:Utc utc1 = check time:utcFromString("2022-02-28T10:15:30.00Z");
decimal seconds = 172800;
time:Utc utc2 = time:utcAddSeconds(utc1, seconds);
io:println(time:utcToString(utc2));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1