Skip to content

Commit

Permalink
feature: LocalDateTime.toYearMonth() 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryJhin committed Aug 11, 2024
1 parent 5bb7389 commit 5ca5293
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package blog.jinhyun.java.time

import java.time.LocalDateTime
import java.time.YearMonth

/**
* [LocalDateTime]의 연도와 월 정보를 [YearMonth]로 변환합니다.
*
* ```kotlin
* val dateTime = LocalDateTime.of(2022, 1, 1, 0, 0)
* val yearMonth = dateTime.toYearMonth()
* println(yearMonth) // 2022-01
* ```
*
* @receiver [LocalDateTime] 객체
* @return [YearMonth] 객체
*/
fun LocalDateTime.toYearMonth() = YearMonth.of(year, month)

0 comments on commit 5ca5293

Please sign in to comment.