どうも、ちょげ(@chogetarou)です。
Dateを使って今日の日付・時刻を取得する方法を紹介します。
方法

Dateを使って今日の日付・時刻を取得するには、引数なしのコンストラクタを使います。
まず、java.util.Dateをインポートします。
import java.util.Date
そして、引数なしのDate()でインスタンスを生成します。
val currentDate = Date()
引数なしのDate()は、今日の日付・時刻を持つDateを生成します。
使用例
import java.util.Date
fun main() {
val currentDate = Date()
println(currentDate)
println(currentDate::class.simpleName)
}
出力:
Mon Aug 01 22:26:20 UTC 2022
Date
コメント