Hi,
How to convert current date to mm dd yyyy format in Java? Share me the program for using in my project.
Thanks
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
Hi,
This example is very good. Congrats for providing such a good example.
Thanks
HI,
If you want to learn Java date conversion in detail then check following tutorials:
Thanks
Ads