Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android问题显示星期几字符串_Android_Sqlite_Time_Gregorian Calendar - Fatal编程技术网

Android问题显示星期几字符串

Android问题显示星期几字符串,android,sqlite,time,gregorian-calendar,Android,Sqlite,Time,Gregorian Calendar,我看到过许多在Android中使用Calendar和GregorianCalendar类处理日期的例子。 最近,我在Android开发者Time文档中遇到了以下问题: Time类可以更快地替代java.util.Calendar和java.util.GregorianCalendar类。Time类的一个实例表示时间上的一个时刻,以第二精度指定 这促使我用更快的时间类函数替换所有日历函数 以下是我读取SQLite数据库中存储的日期的代码: //从SQLite数据库中提取毫秒(长)值 Long ti

我看到过许多在Android中使用Calendar和GregorianCalendar类处理日期的例子。 最近,我在Android开发者
Time
文档中遇到了以下问题:

Time类可以更快地替代java.util.Calendar和java.util.GregorianCalendar类。Time类的一个实例表示时间上的一个时刻,以第二精度指定

这促使我用更快的时间类函数替换所有日历函数

以下是我读取SQLite数据库中存储的日期的代码:

//从SQLite数据库中提取毫秒(长)值
Long timeLong=note.getLong(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DATE))
时间currentTime.set(timeLong)

以下是准备整数值以填充日期选择器并在mPickDate按钮中显示格式化日期字符串的部分代码:

    mDay = currentTime.monthDay;             // Day of the month (0-31)
    mMonth = currentTime.month;              // Month (0-11)
    mYear = currentTime.year;                // Year 
    mPickDate.setText(currentTime.format("%A, %d %b %Y")); // using strftime equivalent to dateFormat = new SimpleDateFormat("E, dd MMM yyyy");
请注意用于获取一周中某一天的长字符串的格式%A。 这部分格式化代码工作得很好,显示了正确的字符串和格式化日期,包括一周中的正确日期

单击mPickDate按钮调用DatePicker小部件,该小部件允许更改和设置新日期

以下代码显示了从日期选择器处理新选择的日期:

    private DatePickerDialog.OnDateSetListener mDateSetListener =
        new DatePickerDialog.OnDateSetListener() {

            public void onDateSet(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
                // new method using Time class
                currentTime.set(dayOfMonth, monthOfYear, year);

                mPickDate.setText(currentTime.format("%A, %d %b %Y"));

                // old method using GregorianCalendar class
                //mCalendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);
                //mPickDate.setText(dateFormat.format(mCalendar.getTime()));                    
            }
        };
mPickDate按钮将显示正确的日期字符串,如在日期选择器中选择的,但星期日(%A)除外,它始终显示为星期日。为什么?

请注意,mPickDate.SetText代码与前面用于格式化按钮日期字符串(从SQLite数据库字段提取)的代码相同

我不得不修改上面的代码,通过添加额外的代码行再次设置currentTime对象中的日期值:

            currentTime.set(dayOfMonth, monthOfYear, year);
            currentTime.set(currentTime.toMillis(true));
            mPickDate.setText(currentTime.format("%A, %d %b %Y"));
我的问题是:为什么必须在上述DatePickerDialog.OnDateSetListener代码中使用currentTime.set过程两次,才能正确显示星期几字符串

这可能是Android
Time
code本身(使用SDK版本16)的问题吗