[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type

1. Prior knowledge

-[Latest] How to build Java environment on Ubuntu

-[Even beginners can do it! ] How to create a Java environment on Windows 10 (JDK14.0.1)

-[Easy-to-understand explanation! ] How to use Java instance

-[Even beginners can do it! ] How to install Eclipse on Windows 10 (Java environment construction)

As prior knowledge, the contents of the above link are required.

2. How to convert from LocalDate type to string and from string to LocalDate type

01.png 01.png

  1. Start Eclipse and select [File (F)]-> [New (N)]-> [Java Project]. 02.png
  2. Enter LocalDateTest in the project name (P), select JavaSE-1.8 for Use JRE (V), and click the Finish (F)> button. 03.png
  3. Right-click on [src] and select [New] → [Class]. 04.png
  4. Enter Test in the name, checkpublic static void main (String [] args) (V)and click theDone (F)button.

Test.java




import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Test {

	public static void main(String[] args) {

		//String to convert
		String date1 = "2020/07/07";

		//String to java.time.Convert to LocalDate
		LocalDate test1 = LocalDate.parse(date1, DateTimeFormatter.ofPattern("yyyy/MM/dd"));

		// java.time.Convert from LocalDate to String
		String test2 = test1.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));

		//Display conversion contents
		System.out.println(date1 + " → "  + test1);
		System.out.println(test1 + " → "  + test2);

	}

}

  1. Enter the above source code in Test.java. 06.png
  2. Right-click on Test.java and select[Run] → [2 Java Application]. 05.png
  3. If it looks like the image, it is successful.

3. Related

-[Useful to remember !!!] Easy creation of constructor and getter / setter in Eclipse -[Useful to remember !!!] Easy creation of inherited class in Eclipse -[Useful to remember !!!] Change MySQL character code -[Even beginners can do it! ] How to write Javadoc -[Easy-to-understand explanation! ] How to use Java overload -[Easy-to-understand explanation! ] How to use Java encapsulation -[Easy-to-understand explanation! ] How to use Java inheritance [Override explanation] -[Easy-to-understand explanation! ] Type conversion of reference type in Java -[Easy-to-understand explanation! ] How to use Java polymorphism -[Easy-to-understand explanation! ] How to use ArrayList [Java] -[Practice! ] Introduction of JFrame (explanation up to screen creation) -[Practice! ] Java database linkage (Connector / J 8.0.20) -[Practice! ] Execution of SQL statement -All about Java programming

Recommended Posts

[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
[Java] How to convert from String to Path type and get the path
How to convert LocalDate and Timestamp
[Android] How to convert a character string to resourceId
Convert String type to Timestamp type
[Java] How to erase a specific character from a character string
I tried to convert a string to a LocalDate type in Java
Change only one character from the String type string to uppercase
[Rails] How to convert from erb to haml
[Java] Convert Object type null to String type
How to convert java.util.Date, java.sql.Date, LocalDate, ZonedDateTime
Type conversion from java BigDecimal type to String type
Ruby How to convert between uppercase and lowercase
[Java] How to convert one element of a String type array to an Int type
How to convert a value of a different type and assign it to another variable
[JSR-310 Date and Time API] Precautions for format definition when converting from Japanese calendar character string to date type
<java> Read Zip file and convert directly to string
Convert Java enum enums and JSON to and from Jackson
[Java] Convert character strings to uppercase / lowercase (AOJ⑨-swap uppercase and lowercase)
How to serialize and deserialize LocalDateTime type with GSON
[Java] How to cut out a character string character by character
How to convert A to a and a to A using AND and OR in Java
How to type backslash \
A memorandum when I investigated how to convert from Epoch Time to Date type in Scala
How to specify character code and line feed code in JAXB
How to write a migration from Rails datetime type to date type
Set the date and time from the character string with POI
How to set character code and line feed code in Eclipse
How to store a string from ArrayList to String in Java (Personal)
How to write and notes when migrating from VB to JAVA
[IOS14] How to get Data type image data directly from PHPickerViewController?
Convert to Ruby Leet string
How to use String [] args
Convert from ○ months to ○ years ○ months
How to convert Java radix
How to get and add data from Firebase Firestore in Ruby
[Swift5] How to communicate from ViewController to Model and pass a value
How to use StringBurrer and Arrays.toString.
How to convert erb file to haml
How to call classes and methods
How to use equality and equality (how to use equals)
How to connect Heroku and Sequel
How to use Java enum type
How to change from HTML to Haml
[Java] How to use substring to cut out a part of a character string
[Rails] How to create a table, add a column, and change the column type
How to create a convenient method that utilizes generics and functional interfaces
[Ruby] I want to make an array from a character string with the split method. And vice versa.