0

In my App, I am using Calendar View. So , I have drawn a custom Calendar View using this tutorial. As I want the selected date format in dd-MM-yyyy so for this I have changed this line

df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

into this,

df = new SimpleDateFormat("dd-MM-yyyy", Locale.US);

And after changing that line when I run my App I got this output,

enter image description here

but when I select any cell its gives correct format of date,

enter image description here

Where am I wrong ?

The whole code is same as tutorial. I've just changed one line.

Please help.

Thanks.

Vivek Todi
  • 361
  • 1
  • 9
  • 24
Android
  • 183
  • 1
  • 13

2 Answers2

0

In CalendarAdapter class no need to change date format.

Use this inside CalendarAdapter.

df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);

When display time in CalendarView.java you can use this

df = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
  • I have already changed line like this `df = new SimpleDateFormat("dd-MM-yyyy", Locale.US);` in `CalendarView.java` but nothing happening.. – Android Feb 07 '14 at 14:08
  • As you told i haven't changed line in `CalendarAdapter` but in `CalendarView` when I changed the line the app got crashed! – Android Feb 07 '14 at 14:32
  • I changed like this, `DateFormat df = new SimpleDateFormat("dd-MM-yyyy", Locale.US); String str=df.format(selectedGridDate); showToast(str);` Is this correct way ? – Android Feb 07 '14 at 14:33
  • Where I am displaying Toast.. I changed like this, DateFormat df = new SimpleDateFormat("dd-MM-yyyy", Locale.US); String str=df.format(selectedGridDate); showToast(str); Is this correct way ? – Android Feb 07 '14 at 14:41
  • i think something wrong there..Now try new thing that don't change date format directly. but get in `"yyyy-MM-dd"` format in whole app then convert string date to another date. Please Refer this [parse-some-string-date-to-another-format](http://stackoverflow.com/questions/21624110/parse-some-string-date-to-another-format/21624214#21624214) – Chirag Ghori Feb 07 '14 at 14:47
0

change this

String gridvalueString = separatedTime[2].replaceFirst("^0*","");// taking last part of date. ie; 2 from 2012-12-02.
int gridvalue = Integer.parseInt(gridvalueString);

to

String gridvalueString = separatedTime[0].replaceFirst("^0*","");// taking last part of date. ie; 2 from 2012-12-02.
int gridvalue = Integer.parseInt(gridvalueString);

because i think your date format is like "dd-MM-yyyy" instead of "yyyy-MM-dd"

Kunu
  • 5,078
  • 6
  • 33
  • 61