如何获得科特林的当前本地日期和时间 [英] How to get current local date and time in Kotlin

查看:71
本文介绍了如何获得科特林的当前本地日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Kotlin的本地时间获取当前日期(月,年,日)和时间(时,分,秒)?

How to get current Date (day month and year) and time (hour, minutes and seconds) all in local time in Kotlin?

我尝试了LocalDateTime.now(),但它给我一个错误,提示Call requires API Level 26 (curr min is 21).

I tried through LocalDateTime.now() but it is giving me an error saying Call requires API Level 26 (curr min is 21).

如何在Kotlin中获取时间和日期?

How could I get time and date in Kotlin?

推荐答案

java.util.Calendar.getInstance() represents the current time using the current locale and timezone.

您还可以选择导入并使用Joda-Time或 Android分支之一.

You could also choose to import and use Joda-Time or one of the forks for Android.

这篇关于如何获得科特林的当前本地日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆