admin管理员组文章数量:1123367
In Android Studio (Kotlin):
val calendar = Calendar.getInstance()
calendar.set(1900, 0, 7, 0, 0, 0)
println(calendar.timeInMillis)
println(calendar.time)
// -2208484952073
// Sun Jan 07 00:00:00 YEKT 1900
In browser (Kotlin):
val calendar = Calendar.getInstance()
val timeZone = 5 * 60 * 60 * 1000
calendar.timeInMillis = -2208484952073 + timtZone
println(calendar.time)
// Sun Jan 07 00:57:27 UTC 1900
Why does it return a different time? 00:57:27 instead of 00:00:00
In Android Studio (Kotlin):
val calendar = Calendar.getInstance()
calendar.set(1900, 0, 7, 0, 0, 0)
println(calendar.timeInMillis)
println(calendar.time)
// -2208484952073
// Sun Jan 07 00:00:00 YEKT 1900
In browser (Kotlin):
val calendar = Calendar.getInstance()
val timeZone = 5 * 60 * 60 * 1000
calendar.timeInMillis = -2208484952073 + timtZone
println(calendar.time)
// Sun Jan 07 00:57:27 UTC 1900
Why does it return a different time? 00:57:27 instead of 00:00:00
Share Improve this question edited 12 hours ago Mark Rotteveel 109k225 gold badges155 silver badges218 bronze badges asked 13 hours ago Feuer und WasserFeuer und Wasser 274 bronze badges 4 |1 Answer
Reset to default 4The difference is that a hundred years Yekaterinburg Time (YEKT) was different, according to this site in 1900 it was UTC +4:02:33.
UPD:
There's definitely a +4:02:33 difference there (Kotlin playground):
import java.util.*
fun main() {
printTime("UTC")
printTime("Asia/Yekaterinburg")
}
fun printTime(timeZone: String) {
val calendar = Calendar.getInstance(TimeZone.getTimeZone(timeZone))
calendar.set(1900, 0, 7, 0, 0, 0)
println(calendar.timeInMillis)
println(calendar.time)
}
Results:
Sun Jan 07 00:00:00 UTC 1900
Sat Jan 06 19:57:27 UTC 1900
本文标签: Kotlin Calendar returns different values in Android studio and kotlin onlineStack Overflow
版权声明:本文标题:Kotlin Calendar returns different values in Android studio and kotlin online - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736564782a1944689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Calendar
, but instead use thejava.time
classes likeZonedDateTime
. – Mark Rotteveel Commented 12 hours agoZonedDateTime.of(1900, Month.JANUARY.getValue(), 7, 0, 0, 0, 0, ZoneId.of("Asia/Yekaterinburg")).getOffset();
produces +04:02:33 andZonedDateTime.of(1900, Month.JANUARY.getValue(), 7, 0, 0, 0, 0, ZoneId.of("Asia/Yekaterinburg")).toInstant().toEpochMilli();
produces -2208484953000 – g00se Commented 12 hours ago