Epoch and Unix Timestamp Conversion in Kotlin
Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. It is a modern programming language that makes developers happier. It provides many date time functions to handle date time functionality.
Here we will explain Kotlin date time functions to get current epoch or Unix timestamp, convert timestamp to date and convert date to epoch or Unix timestamp.
Get current epoch or Unix timestamp in KotlinYou can get the current unix timestamp using currentTimeMillis()
.
System.currentTimeMillis()
Convert epoch or Unix timestamp to date in Kotlin
You can convert unix timestamp to date as follows.
val timeStamp = Timestamp(System.currentTimeMillis())
val date = Date(timeStamp.getTime())
Convert date to epoch or unix timestamp in Kotlin
You can convert the date to unix timestamp using following.
val date = SimpleDateFormat("dd-MM-yyyy").parse("04-07-2025")
println(date.time)
More about date time in Kotlin
Also, read:
- Epoch and Unix Timestamp Conversion in PHP
- Epoch and Unix Timestamp Conversion in Java
- Epoch and Unix Timestamp Conversion in JavaScript
- Epoch and Unix Timestamp Conversion in Perl
- Epoch and Unix Timestamp Conversion in Python
- Epoch and Unix Timestamp Conversion in TypeScript
- Epoch and Unix Timestamp Conversion in MySQL
- Epoch and Unix Timestamp Conversion SQL Server
- Epoch and Unix Timestamp Conversion in C# (C-Sharp)
- Epoch and Unix Timestamp Conversion in Go
- Epoch and Unix Timestamp Conversion in Ruby
- Epoch and Unix Timestamp Conversion in VBA
- Epoch and Unix Timestamp Conversion in MATLAB
- Epoch and Unix Timestamp Conversion in Rust