```io.ktor.util.date.GMTDate``` how to get timest...
# ktor
h
Copy code
io.ktor.util.date.GMTDate
how to get timestamp of next month with GMTDate ๐Ÿ˜ž ?
a
Do you mean the timestamp of a first day of the next month or the timestamp of a current date in a month?
h
like the add method of java.util.Calendar
Copy code
Consider a GregorianCalendar originally set to August 31, 1999. Calling add(Calendar.MONTH, 13) sets the calendar to September 30, 2000.
๐Ÿ˜”
a
You can use the kotlinx-datetime library to achieve the necessary effect:
Copy code
val date = GMTDate(0, 0, 0, 31, io.ktor.util.date.Month.AUGUST, 1999)
val instant = Instant.fromEpochMilliseconds(date.timestamp)
val result = instant.plus(13, DateTimeUnit.MONTH, TimeZone.of("GMT"))
val local = result.toLocalDateTime(TimeZone.of("GMT"))
val newDate = GMTDate(seconds = local.second, minutes = local.minute, hours = local.hour, dayOfMonth = local.dayOfMonth, month = io.ktor.util.date.Month.from(local.monthNumber - 1), year = local.year)
println(newDate.toJvmDate())
Please file a feature request if you want to see this functionality in Ktor.
๐Ÿ™Œ 1
h
ok thx a lot, ๐Ÿ˜˜ u save my day
h
๐Ÿ™Œ 1
๐Ÿ™ 1
h
thx Aleksei and Phillip ^_^