-
Notifications
You must be signed in to change notification settings - Fork 0
MonthDay
java.time.MonthDay 클래스는 월(Month)과 일(Day)을 나타내는 클래스입니다.
주어진 String을 MonthDay로 파싱합니다.
String은 라이브러리 기본 구성의 패턴을 따라야 합니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
val monthDay: MonthDay = "01-01".toMonthDay()
println(monthDay) // --01-01String 값이 지정한 형식이 아니라면 DateTimeParseException이 발생합니다.
val monthDay: MonthDay = "01/01".toMonthDay() // DateTimeParseException주어진 String을 MonthDay로 파싱하고 예외가 발생하면 null을 반환합니다.
String은 라이브러리 기본 구성의 패턴을 따라야 합니다.
import io.github.harryjhin.java.time.extension.toMonthDayOrNull
import java.time.MonthDay
val monthDay: MonthDay? = "01-01".toMonthDayOrNull() // --01-01String 값이 지정한 형식이 아니라면 null을 반환합니다.
val monthDay: MonthDay? = "01/01".toMonthDayOrNull() // null주어진 String을 지정한 패턴을 사용하여 MonthDay로 파싱합니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
val monthDay: MonthDay = "01/01".toMonthDay("MM/dd") // --01-01패턴이 올바른 형식이 아니라면 IllegalArgumentException이 발생합니다.
val monthDay: MonthDay = "01/01".toMonthDay("ABC") // throw IllegalArgumentExceptionString 값이 지정한 형식이 아니라면 DateTimeParseException이 발생합니다.
val monthDay: MonthDay = "01-01".toMonthDay("MM/dd") // throw DateTimeParseException주어진 String을 지정한 패턴을 사용하여 MonthDay로 파싱하고 예외가 발생하면 null을 반환합니다.
import io.github.harryjhin.java.time.extension.toMonthDayOrNull
import java.time.MonthDay
val monthDay: MonthDay? = "01/01".toMonthDayOrNull("MM/dd") // --01-01패턴이 올바른 형식이 아니라면 null을 반환합니다.
val monthDay: MonthDay? = "01/01".toMonthDayOrNull("ABC") // nullString 값이 지정한 형식이 아니라면 null을 반환합니다.
val monthDay: MonthDay? = "01-01".toMonthDayOrNull("MM/dd") // null주어진 String을 지정한 DateTimeFormatter를 사용하여 MonthDay로 파싱합니다.
import io.github.harryjhin.java.time.extension.toDateTimeFormatter
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
import java.time.format.DateTimeFormatter
val formatter: DateTimeFormatter = "MM/dd".toDateTimeFormatter()
val monthDay: MonthDay = "01/01".toMonthDay(formatter) // --01-01String 값이 지정한 형식이 아니라면 DateTimeParseException이 발생합니다.
val monthDay: MonthDay = "01-01".toMonthDay(formatter) // throw DateTimeParseException주어진 String을 지정한 DateTimeFormatter를 사용하여 MonthDay로 파싱하고 예외가 발생하면 null을 반환합니다.
import io.github.harryjhin.java.time.extension.toDateTimeFormatter
import io.github.harryjhin.java.time.extension.toMonthDayOrNull
import java.time.MonthDay
import java.time.format.DateTimeFormatter
val formatter: DateTimeFormatter = "MM/dd".toDateTimeFormatter()
val monthDay: MonthDay? = "01/01".toMonthDayOrNull(formatter) // --01-01MonthDay 인스턴스에서 월(month) 정보를 Period로 가져옵니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import io.github.harryjhin.java.time.extension.months
import java.time.MonthDay
import java.time.Period
val monthDay: MonthDay = "01-01".toMonthDay()
val period: Period = monthDay.months // P1MMonthDay 인스턴스에서 일(day) 정보를 Period로 가져옵니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import io.github.harryjhin.java.time.extension.days
import java.time.MonthDay
import java.time.Period
val monthDay: MonthDay = "01-01".toMonthDay()
val period: Period = monthDay.days // P1DMonthDay 인스턴스에 Period를 더합니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import io.github.harryjhin.java.time.extension.days
import java.time.MonthDay
var monthDay: MonthDay = "01-02".toMonthDay()
monthDay += 1.days // --01-03MonthDay 인스턴스에서 Period를 뺍니다.
import io.github.harryjhin.java.time.extension.toMonthDay
import io.github.harryjhin.java.time.extension.days
import java.time.MonthDay
var monthDay: MonthDay = "01-02".toMonthDay()
monthDay -= 1.days // --01-01MonthDay와 Year를 결합하여 LocalDate 인스턴스를 생성합니다.
import io.github.harryjhin.java.time.extension.at
import io.github.harryjhin.java.time.extension.toMonthDay
import io.github.harryjhin.java.time.extension.toYear
import java.time.MonthDay
import java.time.Year
import java.time.LocalDate
val monthDay: MonthDay = "01-01".toMonthDay()
val year: Year = 2024.toYear()
val date: LocalDate = monthDay at year // 2024-01-01두 MonthDay 인스턴스 사이의 날짜 간격을 계산하여 Period로 반환합니다.
import io.github.harryjhin.java.time.extension.between
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
import java.time.Period
val start: MonthDay = "01-01".toMonthDay()
val end: MonthDay = "02-01".toMonthDay()
val period: Period = start between end // P1MMonthDay 인스턴스를 지정한 패턴을 사용하여 String으로 포매팅합니다.
import io.github.harryjhin.java.time.extension.toString
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
val monthDay: MonthDay = "01-01".toMonthDay()
val string: String = monthDay.toString("MM/dd") // 01/01패턴이 올바른 형식이 아니라면 IllegalArgumentException이 발생합니다.
val string: String = monthDay.toString("ABC") // throw IllegalArgumentExceptionMonthDay 인스턴스를 DateTimeFormatter를 사용하여 String으로 포매팅합니다.
import io.github.harryjhin.java.time.extension.toDateTimeFormatter
import io.github.harryjhin.java.time.extension.toString
import io.github.harryjhin.java.time.extension.toMonthDay
import java.time.MonthDay
import java.time.format.DateTimeFormatter
val formatter: DateTimeFormatter = "MM/dd".toDateTimeFormatter()
val monthDay: MonthDay = "01-01".toMonthDay()
val string: String = monthDay.toString(formatter) // 01/01