Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to format Java LocalDateTime as ISO_DATE_TIME format
At first, set the date:
LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);
Now, format the datetime as ISO_DATE_TIME format:
String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
Example
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
public class Demo {
public static void main(String[] args) {
LocalDateTime dateTime = LocalDateTime.of(2019, Month.JULY, 9, 10, 20);
System.out.println("DateTime = "+dateTime);
String str = dateTime.format(DateTimeFormatter.ISO_DATE_TIME);
System.out.println("Formatted date = "+str);
}
}
Output
DateTime = 2019-07-09T10:20 Formatted date = 2019-07-09T10:20:00
Advertisements