
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Timestamp to DateTime in Kotlin
Kotlin is a statistically typed language and it is based on Java, hence all the Java code can easily be compiled within Kotlin code. In this article, we will see how we can generate the current local date and time in Kotlin.
As Kotlin is interoperable with Java, we will be using Java utility class and Simple Date Format class in order to convert TimeStamp into DateTime.
Example – Converting DateTime using Java util class
As Kotlin is comparable with the JVM, we can use the Java util class in order to convert the TimeStamp into DateTime.
import java.text.SimpleDateFormat import java.util.* fun main(args: Array<String>) { val simpleDate = SimpleDateFormat("dd/M/yyyy hh:mm:ss") val currentDate = simpleDate.format(Date()) println(" Current DateTime is -"+currentDate) }
Output
On execution, it will print the current Date and Time.
Current DateTime is -28/2/2022 11:25:11
Advertisements