How do I convert the date from a getDateInstance to a SimpleDateFormat with out the date changing?

StackOverflow https://stackoverflow.com/questions/20510613

  •  31-08-2022
  •  | 
  •  

Question

I am trying to get the proper date for my android application but it does not seem to be working.

When I use this code

String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
if(btn==v){
    view.setText(currentDateTimeString);
}

I get the correct date printed out as Dec 10, 2013.

But when I try to convert the date into a simple date format, the program always stops working.

String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
SimpleDateFormat dateformat = new SimpleDateFormat("MM/FF");
String cdate = dateformat.format(currentDateTimeString);
if(btn==v){
    view.setText(cdate);
}

Also when I use the Simple Date format like this I get a completely different date, 12/02

    Calendar cdate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MM/FF");
if(btn==v){
    view.setText(sdf.format(cdate.getTime()));
}

I am trying to get the current date to display as Month/Day, any help would be greatly appreciated.

Was it helpful?

Solution

FF is day in week. Try dd for day of month.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top