I have a datepicker. My app is pushing a notification. I want to display the date in 01-07-2013 MM-dd-yyyy format. Please check my code below:
//---Button v
I want to display the date in 01-07-2013 MM-dd-yyyy format.
yes you can Do this by Below Steps.
Step 1: you First have to Convert your String to Particular Date Format
Step 2: Using SimpleDateFormat Convert your Date to MM-dd-yyyy format
Step 3: Convert to String and Use it.
you can User Below Code for this.
public class DateFormat {
public static void main(String[] args) {
// Put here what your are getting as String
String mytime="Jan 7, 2013";
SimpleDateFormat dateFormat = new SimpleDateFormat(
"MMM dd, yyyy"); //Step1: Convert yout String to perticular Date Formate according to your Date String your are getting
Date myDate = null;
try {
myDate = dateFormat.parse(mytime);
} catch (ParseException e) {
e.printStackTrace();
}
//Step2
SimpleDateFormat timeFormat = new SimpleDateFormat("MM-dd-yyyy");
String finalDate = timeFormat.format(myDate);
//Step3: Here you will get your Final Date. Set your String now to textview.
}
}
Hope it will help you.