What is the LocalDateTime class? [Java beginner] -Date and time class-

Let's get rid of it. I tried to summarize the date and time class ☺

■ What is the LocalDateTime 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.

■ What is the DateTimeFomatter class?

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.

■ Are there any other date and time classes?

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

What is the LocalDateTime class? [Java beginner] -Date and time class-
[Java] Get the date with the LocalDateTime class
What is the BufferedReader class?
[Java] What is class inheritance?
[Java basics] What is Class?
What is the difference between a class and a struct? ?? ??
[JAVA] What is the difference between interface and abstract? ?? ??
What is the difference between Java EE and Jakarta EE?
[MySQL] [java] Receive date and time
[Java] Use ResolverStyle.LENIENT to handle the date and time nicely
The design concept of Java's Date and Time API is interesting
The relationship between strict Java date checking and daylight savings time
[Java] What is the difference between form, entity and dto? [Bean]
What is a class in Java language (3 /?)
What is the best file reading (Java)
What is a class in Java language (1 /?)
What is Java and Development Environment (MAC)
What is a class in Java language (2 /?)
[Java] How to set the Date time to 00:00:00
What is the main method in Java?
What is java
Date and time
What is Java <>?
What is Java
[Java] How to get the current date and time and specify the display format
Format the date and time given by created_at
What is the volatile modifier for Java variables?
What is the difference between SimpleDateFormat and DateTimeFormatter? ??
The date time of java8 has been updated
[Java] How to use Calendar class and Date class
[Java] Get and display the date 10 days later using the Time API added from Java 8.
[Java] Calculate the day of the week from the date (Calendar class is not used)
Parse the date and time string formatted by the C asctime function in Java
[Java] Date / time operations
What is Java Encapsulation?
What is Java technology?
What is Java API-java
Java Unit Test Library-Determine if Artery-Date, Calendar, long is the current date and time (specify tolerance in minutes)
[Java] What is flatMap?
[Java] What is JavaBeans?
[Java] What is ArrayList?
The comparison of enums is ==, and equals is good [Java]
What is the difference between System Spec and Feature Spec?
[Rails] What is the difference between redirect and render?
[Java] Get the date 10 days later with the Calendar class
Learn for the first time java # 3 expressions and operators
What is the difference between skip and pending? [RSpec]
[Java Silver] What are class variables instance variables and local variables?
What is Java Assertion? Summary.
[MySQL] [java] Receive date and time
What is a wrapper class?
Find the address class and address type from the IP address with Java
What is the pluck method?
[Rails] What is the difference between bundle install and bundle update?
Set the date and time from the character string with POI
Java class definition and instantiation
What is a Java collection?
Sample code to parse date and time with Java SimpleDateFormat
[Java] com.sun.glass.WindowEvent is imported and the window does not close
[Java] What is jaee j2ee?
What is the difference between an action and an instance method?