如何在 Kotlin 中以本地时间获取当前日期(日月和年)和时间(小时、分钟和秒)?
我尝试通过 LocalDateTime.now()
但它给了我一个错误提示 Call requires API Level 26 (curr min is 21)
。
如何在 Kotlin 中获取时间和日期?
最佳答案
试试这个:
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm:ss")
val currentDate = sdf.format(Date())
System.out.println(" C DATE is "+currentDate)
https://stackoverflow.com/questions/47006254/
相关文章:
android - 无法获取提供商 com.google.android.gms.ads.Mobil
kotlin - 字符串插值在 Kotlin 中是如何工作的?
android - 在 android studio 中运行带有 main 函数的单个 kotlin
android - Dagger 2 与 Kotlin 的多重绑定(bind)
android - Kotlin 等价于 Java 的 equalsIgnoreCase
kotlin - 传递 null 时,有没有办法在非可选参数上使用默认值?
java - Android Studio 3.1.3 - Unresolved reference
android - 在 Kotlin 中的原始类型属性上不允许使用 lateinit 修饰符