

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 use the SimpleDateFormat class to convert a Java Date to a formatted String?
The Java SimpleDateFormat class provides convert between a Java String to a Date or Date to String.
Example
import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calendar; public class SimpleDateFormatTest { public static void main(String[] args) { // get today's date Date today = Calendar.getInstance().getTime(); // create a date "formatter" SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss"); // create a new String using the date format String formattedDate = formatter.format(today); // prints converted date to string format System.out.println(" Date is:" + formattedDate); } }
Output
Date is:2019-06-04-05.55.13
- Related Questions & Answers
- How to Format a Date String using SimpleDateFormat in Java?
- Java Program to convert a String to Date
- How to convert a Python date string to a date object?
- How to convert String to Date in java?
- How to convert a JavaScript date object to a string?
- How to convert a string to date in MySQL?
- How to convert a string to a Python class object?
- Java Program to Convert String to Date
- Convert String to Date in Java
- How to convert Date to String in Java 8?
- How to convert a date to a string using the universal time convention?
- Java Program to format date with SimpleDateFormat
- How to convert a Date value to string in JDBC?
- How to convert a MySQL date to JavaScript date?
- How to convert a string in to date object in JavaScript?
Advertisements