I need to add x days to an instant. However, when ...
# kotlinx-datetime
s
I need to add x days to an instant. However, when I was using
java.util.Calendar
, I was adding the days in hours to avoid DST/ST crossover issues. Is
instant + x.days
equivalent to
calendar.set(Calendar.HOUR, 24 * x)
?
k
x.days
yields a duration and not a calendar period. The duration of days defined by
days
is 24 hours and will be inaccurate during DST. You should use a
DateTimePeriod
for your purposes.
Copy code
myInstant.plus(period = DateTimePeriod(days = 5), timeZone = myTimeZone)
thank you color 1