[JAVA] How to get the current date as a string in yyyyMMdd format

This is a sample to get the current date in yyyyMMdd format.

Use SimpleDateFormat. Specify the format in the following format.

SimpleDateFormat Object name = new SimpleDateFormat (“format pattern”)
import java.text.SimpleDateFormat;
import java.util.Calendar;

		Calendar cl = Calendar.getInstance();

		//Output the date in the form of yyyyMMdd
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String str = sdf.format(cl.getTime());
		System.out.println(str);

		//Date yyyy/MM/Output in the form of dd
		SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd");
		String str1 = sdf1.format(cl.getTime());
		System.out.println(str1);
```


Recommended Posts

How to get the current date as a string in yyyyMMdd format
How to get the date in java
How to get date data in Ruby
[Java] How to get the current directory
[Java] How to get to the front of a specific string using the String class
How to get the absolute path of a directory running in Java
How to get the ID of a user authenticated with Firebase in Swift
How to run the SpringBoot app as a service
How to write a date comparison search in Rails
How to get the class name / method name running in Java
How to create a form to select a date from the calendar
How to store a string from ArrayList to String in Java (Personal)
How to get the longest information from Twitter as of 12/12/2016
How to select a specified date by code in FSCalendar
How to add the same Indexes in a nested array
[jsoup] How to get the full amount of a document
I want to find the MD5 checksum of a file in Java and get the result as a string in hexadecimal notation.
How to get parameters in Spark
What to do when Cannot format given Object as a Date in convertDateTime of JSF
Get the current date and time by specifying the time zone in Thymeleaf
How to get the id of PRIMAY KEY auto_incremented in MyBatis
How to store the information entered in textarea in a variable in the method
How to output a list of strings in JSF as comma-separated strings
[Java] How to convert from String to Path type and get the path
How to check for the contents of a java fixed-length string
How to get the length of an audio file in java
How to get JDK 11 on your mac in a comfortable way
How to implement date calculation in Java
How to insert a video in Rails
[Java] How to set the Date time to 00:00:00
How to fix system date in JUnit
Notation to put a variable in a string
How to publish a library in jCenter
[Rails] How to get the user information currently logged in with devise
How to get the value after "_" in Windows batch like Java -version
How to get the setting value (property value) from the database in Spring Framework
How to change the value of a variable at a breakpoint in intelliJ
How to reference a column when overriding the column name method in ActiveRecord
How to create your own annotation in Java and get the value
[Swift] How to get the number of elements in an array (super basic)
How to get the query string to actually issue when using PreparedStatement with JDBC
How to get keycloak credentials in interceptor class
Convert to a tag to URL string in Rails
graphql-ruby: How to get the name of query or mutation in controller Note
How to check the logs in the Docker container
[Android] How to convert a character string to resourceId
How to display a web page in Java
How to add sound in the app (swift)
How to get Class from Element in Java
How to get today's day of the week
[Rails] How to get rid of flash messages in a certain amount of time
How to run a djUnit task in Ant
[Java] How to easily get the longest character string of ArrayList using stream
How to add a classpath in Spring Boot
How to create a theme in Liferay 7 / DXP
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to make a unique combination of data in the rails intermediate table
[Ruby] How to generate a random alphabet string
How to get the date from the JavaScript Date type that C # developers are addicted to
[Java] How to get the redirected final URL