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
How to convert date to string in Java in yyyy-mm-dd format
How to format current date into yyyy-mm-dd in Java
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
convert yyyy-mm-dd hh mm ss to date in sql
validationrule for date as format yyyy-mm-dd in drools
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
How to convert date to UTC format in Java?
Mysql Date Expression
Simple date formatter example
Mysql Date Format Convert
How to convert date to string in Java?
Mysql Date Type
String to date with no format
select date in desired format
How to Convert String to Date?
java format date
Mysql Date Format codes
How to get the current date in Java?
Get current Date and Time
JDBC : Current Date
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
Convert String into date
How to calculate sum of HH:MM:SS Format?

Ads