How to get current Date (day month and year) and time (hour, minutes and seconds) all in local time in Kotlin?
I tried through LocalDateTime.now()
but it is giving me an error saying Call requires API Level 26 (curr min is 21)
.
How could I get time and date in Kotlin?
This example demonstrates how to get the current time and date in an Android app Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
To get local formatting use getDateInstance() , getDateTimeInstance() , or getTimeInstance() , or use new SimpleDateFormat(String template, Locale locale) with for example Locale.US for ASCII dates.
getInstance(). getTime(); System. out. println("Current time => " + c); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate = df.
Try this :
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm:ss") val currentDate = sdf.format(Date()) System.out.println(" C DATE is "+currentDate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With