Signed-off-by: rtc <rtc@qq.com>

pull/34/head
rtc 2 years ago
parent c2f2f6e4b5
commit 1941c059c3

@ -345,63 +345,70 @@ public class DateTimePicker extends FrameLayout {
* @return The current month in the year * @return The current month in the year
*/ */
public int getCurrentMonth() { public int getCurrentMonth() {
return mDate.get(Calendar.MONTH); return mDate.get(Calendar.MONTH); // 获取日期对象的月份字段
} }
/** /**
* Set current month in the year *
* *
* @param month The month in the year * @param month 00
*/ */
public void setCurrentMonth(int month) { public void setCurrentMonth(int month) {
if (!mInitialising && month == getCurrentMonth()) { if (!mInitialising && month == getCurrentMonth()) {
return; return;
} }
mDate.set(Calendar.MONTH, month); mDate.set(Calendar.MONTH, month); // 设置日期对象的月份
updateDateControl(); updateDateControl(); // 更新日期选择器控件
onDateTimeChanged(); onDateTimeChanged(); // 通知日期时间改变
} }
/** /**
* Get current day of the month *
* *
* @return The day of the month * @return
*/ */
public int getCurrentDay() { public int getCurrentDay() {
return mDate.get(Calendar.DAY_OF_MONTH); return mDate.get(Calendar.DAY_OF_MONTH); // 获取日期对象的天数字段
} }
/** /**
* Set current day of the month *
* *
* @param dayOfMonth The day of the month * @param dayOfMonth
*/ */
public void setCurrentDay(int dayOfMonth) { public void setCurrentDay(int dayOfMonth) {
if (!mInitialising && dayOfMonth == getCurrentDay()) { if (!mInitialising && dayOfMonth == getCurrentDay()) {
return; return;
} }
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth); // 设置日期对象的天数字段
updateDateControl(); updateDateControl(); // 更新日期选择器控件
onDateTimeChanged(); onDateTimeChanged(); // 通知日期时间改变
} }
/** /**
* Get current hour in 24 hour mode, in the range (0~23) * 240~23
* @return The current hour in 24 hour mode *
* @return 24
*/ */
public int getCurrentHourOfDay() { public int getCurrentHourOfDay() {
return mDate.get(Calendar.HOUR_OF_DAY); return mDate.get(Calendar.HOUR_OF_DAY); // 获取日期对象的小时字段24小时制
} }
/**
*
*
* @return
*/
private int getCurrentHour() { private int getCurrentHour() {
if (mIs24HourView){ if (mIs24HourView) { // 如果是24小时制
return getCurrentHourOfDay(); return getCurrentHourOfDay(); // 直接获取当前的小时
} else { } else { // 如果是12小时制
int hour = getCurrentHourOfDay(); int hour = getCurrentHourOfDay(); // 获取当前的小时
if (hour > HOURS_IN_HALF_DAY) { if (hour > HOURS_IN_HALF_DAY) { // 如果大于12小时
return hour - HOURS_IN_HALF_DAY; return hour - HOURS_IN_HALF_DAY; // 返回减去12小时的小时数
} else { } else { // 如果小于等于12小时
return hour == 0 ? HOURS_IN_HALF_DAY : hour; return hour == 0 ? HOURS_IN_HALF_DAY : hour; // 如果小时为0则返回12小时否则返回当前的小时
} }
} }
} }

Loading…
Cancel
Save