I want to date format change with java code.
Input value will be "2015/07/02".
Output value want to be "02-JUL-15".
I want to know date format of "02-JUL-15". How to change the date format? Please help!
I want to date format change with java code.
Input value will be "2015/07/02".
Output value want to be "02-JUL-15".
I want to know date format of "02-JUL-15". How to change the date format? Please help!
Simplest way to do this is to use SimpleDateFormat
in java,
DateFormat date = new SimpleDateFormat("dd-MMM-yy");
date.format(yourdate); //yourdate in this case is "2015/07/02" wherever that is stored
To answer you question, the format of "02-JUL-15" is dd-MMM-yy
, Try not to use java.util.date
most of its methods have been deprecated
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* This Example
* Takes an input in the format YYYY/MM/DD i.e 2015/07/24
* and converts back in the format DD-MON-YY ie 24-JUL-15
*/
public class DateConverter1 {
public static void main(String...strings) throws ParseException {
// define the date format in which you want to take the input
// i.e YYYY/MM/DD correspond to yyyy/MM/dd
DateFormat inputDateFormat = new SimpleDateFormat("yyyy/MM/dd");
// convert your date into desired input date format
Date inputDate = inputDateFormat.parse("2015/07/20");
// above lines gives Parse Exception if date is UnParsable
// define the date format in which you want to give output
// i.e dd-MMM-yy
DateFormat outputDateFormat = new SimpleDateFormat("dd-MMM-yy");
// don't assign it back to date as format return back String
String outputDate = outputDateFormat.format(inputDate);
System.out.println(outputDate);
}
}
Output:
20-Jul-15
@Ankur Anand And @ Manish Mallavarapu ⇒ now, I found solution about "dd-MMM-yy". when we set up format "English (United States)" at region and language within my pc, we found output "20-Jul-15". But, when we set up format "japanese" at region and language, we found output "20-07-15".