Let's get rid of it. I tried to summarize the date and time class ☺
New API introduced from Java 8. 【Feature】 -Date and time without a time zone. -Has an instance of LocalDate and LocalTime inside. ・ Example: 2015-12-15T23: 30: 59.999
If you write it in code, you can do it like this.
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class test01 {
public static void main(String[] args) {
//Generate current date and time;
LocalDateTime d = LocalDateTime.now();
System.out.println("Current date and time:" + d); //Current date and time:2020-04-15T15:57:33.884
//Generate date
LocalDate ld2 = LocalDate.of(2020, 4, 15);
System.out.println("date:" + ld2); //date:2020-04-15
//Generate time
LocalTime lt1 = LocalTime.now();
System.out.println("time:" + lt1); //time:15:57:33.886
}
}
It may be useful to know.
java.time.fomat.DateTimeFormatter 【Feature】 -Output and analyze date / time character strings. -Equivalent to SimpleDateFormat of the old API. -Formatters such as ISO standard format are also defined as constants.
java.time.ZonedDateTime Date and time with time zone. Example: 2015-12-15T23: 30: 59.999 + 09: 00 [Asia / Tokyo]
___________________________
java.time.OffsetDateTime Date and time with offset. Example: 2015-12-15T23: 30: 59.999 + 09: 00
___________________________
java.time.ZoneId Time zone ID. (Asia / Tokyo, etc.) Used when creating an instance of ZonedDateTime.
___________________________
java.time.ZoneOffset Timezone offset from Greenwich / UTC (for example, +09: 00). OffsetDateTime used when creating an instance.
___________________________
java.time.temporal.ChronoField An enumeration that represents a date and time field such as "year" or "month". Implementation class of TemporalField interface. Used in methods that have TemporalField type parameters, such as when getting a value from a datetime class.
___________________________
java.time.temporal.ChronoUnit An enumeration type that represents the unit of date and time, such as "1 year" and "1 month". Implementation class of TemporalUnit interface. Used in methods with TemporalUnit type parameters.
See you again
Recommended Posts