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

Ads
 

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

Hi,

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

In my program I have to display the current date in the dd-mm-yyyy format to user on the website.

How to achieve the conversion of current date into this desired format?

Thanks

View Answers

March 2, 2016 at 4:04 PM

Hi,

Here is the source code for formatting the current date into dd-mm-yyyy format:

package net.roseindia;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/*
 * This program converts current date into 
 *  dd-mm-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 dd-mm-yyyy
            Date currentDate = new Date();
            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

Ads









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
Java convert string to date from format yyyy-mm-dd hh mm ss
How to get today's date in java in mm/dd/yyyy format?
validationrule for date as format yyyy-mm-dd in drools
convert yyyy-mm-dd hh mm ss to date in sql
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
Simple date formatter example
Mysql Date Type
Mysql Date Format Convert
select date in desired format
String to date with no format
How to convert date to string in Java?
java format date
Mysql Date Format codes
How to Convert String to Date?
JDBC : Current Date
date format to be updated with current date time
Get current Date and Time
How to get the current date in Java?

Ads