- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to format date in mm-dd-yyyy hh:mm:ss format
Let us format date in mm-dd-yyyy hh:mm:ss format −
// displaying date in mm-dd-yyyy hh:mm:ss format Format f = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss"); String str = f.format(new Date()); System.out.println("Current Date in MM-dd-yyyy hh:mm:ss format = "+str);
Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −
import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;
The following is an example −
Example
import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date and time Calendar cal = Calendar.getInstance(); SimpleDateFormat simpleformat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z"); System.out.println("Today's date and time = "+simpleformat.format(cal.getTime())); // displaying date in mm-dd-yyyy hh:mm:ss format Format f = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss"); String str = f.format(new Date()); System.out.println("Current Date in MM-dd-yyyy hh:mm:ss format = "+str); // displaying date f = new SimpleDateFormat("dd/MMMM/yyyy"); String strDate = f.format(new Date()); System.out.println("Current Date = "+strDate); // current time f = new SimpleDateFormat("HH.mm.ss Z"); String strTime = f.format(new Date()); System.out.println("Current Time = "+strTime); } }
Output
Today's date and time = Mon, 26 Nov 2018 09:34:11 +0000 Current Date in MM-dd-yyyy hh:mm:ss format = 11-26-2018 09:34:11 Current Date = 26/November/2018 Current Time = 09.34.11 +0000
- Related Articles
- How to format JavaScript date into yyyy-mm-dd format?
- How to parse Date from String in the format: dd/MM/yyyy to dd/MM/yyyy in java?
- Convert MySQL date format from yyyy-mm-ddThh:mm:ss.sssZ to yyyy-mm-dd hh:mm:ss ?
- MySQL date format DD/MM/YYYY select query?
- Program to reformat date in YYYY-MM-DD format using Python
- Accepting date strings (MM-dd-yyyy format) using Java regex?
- MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format
- MySQL date format to convert dd.mm.yy to YYYY-MM-DD?
- Get date format DD/MM/YYYY with MySQL Select Query?
- How to format a string to date in as dd-MM-yyyy using java?
- Get today's date in (YYYY-MM-DD) format in MySQL?
- How to insert mm/dd/yyyy format dates in MySQL?
- Change date format (in DB or output) to dd/mm/yyyy in PHP MySQL?
- Format date with SimpleDateFormat('MM/dd/yy') in Java
- How to convert MM/YY to YYYY-MM-DD in MYSQL?

Advertisements