How to convert current date to mm dd yyyy format in Java?

How to convert current date to mm dd yyyy format in Java?

Hi,

How to convert current date to mm dd yyyy format in Java? Share me the program for using in my project.

Thanks

View Answers

March 2, 2016 at 4:30 PM

Hi,

Please find the source code for converting current date into MM-dd-yyyy format.

Here is full code:

package net.roseindia;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
 * This program converts current date into 
 *  MM-dd-yyyy format. You can also change the format
 *  to convert the current date into desired format
 */
public class CurrentDateToString {
    public static void main(String[] args) {
        try {
            //Current date to mm-dd-yyyy
            Date currentDate = new Date();
            DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
            //DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
            String strCurrentDate = df.format(currentDate);
            System.out.println("Date is " + strCurrentDate);
        } catch (Exception e) {
            System.out.println("Exception :" + e);
        }

    }
}

Thanks


July 21, 2017 at 3:50 AM

Hi,

This example is very good. Congrats for providing such a good example.

Thanks









Related Tutorials/Questions & Answers:
How to convert current date to dd mm yyyy format in Java?
How to convert current date to mm dd yyyy format in Java?
Advertisements
c# current date in yyyy-MM-dd format
How to format current date into yyyy-mm-dd in Java
How to convert date to string in Java in yyyy-mm-dd format
How to convert string to date in java in yyyy-mm-dd format?
how to format date from yyyy-mm-dd to dd-mm-yyyy
get current date in java in yyyy mm dd hh mm ss format
php date format yyyy-mm-dd
Java convert string to date from format yyyy-mm-dd hh mm ss
validationrule for date as format yyyy-mm-dd in drools
convert yyyy-mm-dd hh mm ss to date in sql
How to get today's date in java in mm/dd/yyyy format?
how to convert the entire column field of table to dd/mm/yyyy format in microsoft sql server?
convert current date into date format
yyyy-mm-dd validation in javascript
Mysql Date Expression
How to convert date to UTC format in Java?
Date validation in JSP
Mysql Date Format Convert
Mysql Date Type
Simple date formatter example
date format - Java Beginners
select date in desired format
String to date with no format
java format date
date format - Date Calendar
How to convert date to string in Java?
date format to be updated with current date time
date format - JSP-Servlet
How to calculate sum of HH:MM:SS Format?
JDBC : Current Date
Mysql Date Format codes
How to Convert String to Date?
String to Date format
Current Date iPhone SDK
How to get the current date in Java?
Get current Date and Time
Convert Date to GMT
JDBC: Get current Date and Time Example
how to get date format in string from date object containing real date in java
how to get date format in string from date object containing real date in java
Date auto format
Convert String into date
struts2.2.1 date Format example
Change Date Format - Development process
Iphone Show Current Date & Time
Struts 2 Date Format Examples
how to get current date without system date
Insert current date into MYSQL database

Ads