はじめに
今回は自分が最近カレンダー機能などを実装していて調べたことなどを紹介していこうと思います
本文
monthとmonthValueの違い
返却物を見てみるとMonth型とInt型で何が違うんだろうとなりますが
中身を見てみると至極単純でmonthはJANUARYなどの文字列で、monthValueは1などの数値で返ってくるものです
表示をするのに使いたい場合はmonthValue比較やLocalDateへの代入に使うのはmonthといった形になります
月末取得
自分は今までカレンダーに変換してDAY_OF_MONTHで取得してましたが、実はlengthOfMonth()といった形で取得することができます
stringとの相互変換
// String to Date
val formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd")
val localDate = LocalDate.parse(this, formatter)
// Date to String
this.format(DateTimeFormatter.ofPattern("yyyy-MM"))
LocalDateTimeへの変換
val dateList = this.split("/")
LocalDateTime.of(dateList.first().toInt(), dateList[1].toInt(), dateList.last().toInt(), 0, 0)
最後に
今回はタイトルにあるように完全に備忘録としての役目が強いですが、どなたかのお役に立てると幸いです