开发者

Having trobule with displaying the calendars correct date

So my widget pulls up correctly but it wont display the correct selection once the user has made a choice. Here is my code.

SimpleDateFormat dayFormatter = new SimpleDateFormat("EEEE, MMMM FF, yyyy");
Calendar cal = Calendar.getInstance();

This is run at the beginning of my code and when the widget get pulled up it displays the correct date. It might have something to do with why I have my original problem but I am at a lost and 开发者_JAVA技巧don't know how to fix this.

DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, monthOfYear);
        cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);

        int w = cal.get(Calendar.DAY_OF_WEEK);
        Date z = cal.getTime();
        description.setText(gDate.date(w, year, monthOfYear + 1, dayOfMonth) + 
                "\n" + dayFormatter.format(z));

And here is the output.

Monday, July 14, 2011

Monday, July 02, 2011

gDate.date(w, year, monthOfYear + 1, dayOfMonth)

This code above is a class I created to do this with a string before I learned about SimpleDateFormat. This is the string that is on top and displays the right date. Also I don't understand why the second date starts where it is.


Change your pattern from "EEEE, MMMM FF, yyyy" to "EEEE, MMMM dd, yyyy"

FF is day of week in month, dd is day in month. See the javadoc for SimpleDateFormat

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜