[JAVA] Date and time

It's a compilation for personal study

Date and time

Java SE 8 adds a new API for handling dates and times

class

LocalDate

Class that manages ** dates **

LocalTime

** Class that manages time without time zone ** Time can be represented to nanosecond accuracy

DateTimeFormatter

Class to change to the specified ** date pattern ** There are three types: "predefined standard formatter", "locally specific formatter", and "formatter with custom pattern" (more complex formatter provided by ** DateTimeFormatterBuilder **).

Duration

Class that manages ** time difference **

Period

A class that manages ** date differences **

ZonedDateTime

** Class that manages time with time zone **

Method

of method

Method used when instantiating by specifying the date

now method

Method to use when you want to instantiate at the current time

parse method

A method that converts a string date into date and time information.

format method

Method to convert date information to string Predefined standard formatters are defined in ** java.time.format. DateTimeFormatter class **

Formatter Example
BASIC_ISO_DATE 20191213
ISO_ZONED_DATE_TIME 2019-12-13T00:00:00+09:00[Asia/Tokyo]
ISO_INSTANT 2019-12-12T15:00:00Z
ISO_DATE_TIME 2019-12-13T00:00:00

-** ISO_ZONED_DATE_TIME ** and ** ISO_INSTANT ** are the formatters of ** ZonedDateTime **, which represent the time with zones.

until method

** LocalDate ** is a method to calculate ** date difference **, ** LocalTime ** is a method to calculate ** time difference **

between method

** Period ** is a method that calculates ** date difference **, ** Duration ** is a method that calculates ** time difference **

toDays, toHours, toMinutes, toMillis, toNanos methods

** Durtion ** has methods for each unit you want to get the time difference, such as day, hour, minute, second, nanosecond.

Recommended Posts

Date and time
[MySQL] [java] Receive date and time
Date () and Calendar ()
Explanation of Ruby Time and Date objects
[Java] Date / time operations
Format the date and time given by created_at
Date and time acquisition method using DateAndTime API
AWS and on-premise time lag
Change date and time to Japanese notation in Rails
[Rails] Precautions when comparing date and time with DateTime
Usability of date and time classes in each language
Handling of date and time in Ruby. Use Date and Time properly.
Handle Java 8 date and time API with Thymeleaf with Spring Boot
What is the LocalDateTime class? [Java beginner] -Date and time class-
Set the date and time from the character string with POI
Sample code to parse date and time with Java SimpleDateFormat
[Rails] Search method when date and time have each column
[Java] Use ResolverStyle.LENIENT to handle the date and time nicely
[Rails] Save start time and end time
[Ruby] Date, Time, Datetime class basics
Check the actual date and time at parse with Java's SimpleDateFormat
Get the current date and time by specifying the time zone in Thymeleaf
The design concept of Java's Date and Time API is interesting
The relationship between strict Java date checking and daylight savings time
== and equals
[Java] How to get the current date and time and specify the display format
Date processing
Distinguish between runtime and compile time polymorphism
[Java] How to set the Date time to 00:00:00
Java 8 to start now ~ Date time API ~
Oracle Select SQL date parameters take time
How to display today's date and time by default: Remove seconds or less
[Java] Get and display the date 10 days later using the Time API added from Java 8.
Parse the date and time string formatted by the C asctime function in Java
About date / time type of Doma2 entity class
The date time of java8 has been updated
Summary of Japan time setting and display method
java algorithm Artery Time rounding up and down
[Java] How to use Calendar class and Date class