calendar.MINUTE 和 calendar.get(Calendar.MINUTE) 在 Android 中的区别
Difference between calendar.MINUTE and calendar.get(Calendar.MINUTE) in Android
我有两个 Calendar
变量命名为 calendar1
和 calendar2
其中存储了一些日历值。
我想比较这些变量的 MINUTE
值。
我找到了两种方法,但我想知道有什么区别以及哪一种是正确的。
if(calendar1.MINUTE == calendar2.MINUTE)
和
if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))
提前致谢。
MINUTE
returns 整数形式的分钟数:EG(13:04 -> MINUTE 是 4)
get(int field)
-> returns 通过先调用 complete()
计算字段值后给定字段的值。
complete()
-> 如果尚未设置时间,则根据字段计算时间。
calendar1.MINUTE
表示您正在访问 Calendar
class 的 static
常量之一。这与 Calendar.MINUTE
相同。
不应使用对象访问常量字段(例如 calendar1.MINUTE)。
当你调用calendar1.get()
时,你需要传递你想要检索日历的哪个字段,MINUTE
、HOUR
、MILLISECOND
、YEAR
, MONTH
, DAY_OF_MONTH
关于这条线
if(calendar1.MINUTE == calendar2.MINUTE)
你只是比较两个常量,这总是 return true
第二行正确
if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))
好的,这是对您问题的回答。
Calender.MINUTE : - 它给出不为零的分钟。如果分钟在 1 到 9 之间。
例如:我的设备上有时间 12:09 但它显示为 12:9
cal.MINUTE : - 这是用于 Calendar 方法调用的静态最终整数。
并且从实例化对象调用 static 成员是不好的做法。
因此,通过 cal.get(Calendar.MINUTE);
获得正确值的最佳方法。
我有两个 Calendar
变量命名为 calendar1
和 calendar2
其中存储了一些日历值。
我想比较这些变量的 MINUTE
值。
我找到了两种方法,但我想知道有什么区别以及哪一种是正确的。
if(calendar1.MINUTE == calendar2.MINUTE)
和
if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))
提前致谢。
MINUTE
returns 整数形式的分钟数:EG(13:04 -> MINUTE 是 4)
get(int field)
-> returns 通过先调用 complete()
计算字段值后给定字段的值。
complete()
-> 如果尚未设置时间,则根据字段计算时间。
calendar1.MINUTE
表示您正在访问 Calendar
class 的 static
常量之一。这与 Calendar.MINUTE
相同。
不应使用对象访问常量字段(例如 calendar1.MINUTE)。
当你调用calendar1.get()
时,你需要传递你想要检索日历的哪个字段,MINUTE
、HOUR
、MILLISECOND
、YEAR
, MONTH
, DAY_OF_MONTH
关于这条线
if(calendar1.MINUTE == calendar2.MINUTE)
你只是比较两个常量,这总是 return true
第二行正确
if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))
好的,这是对您问题的回答。
Calender.MINUTE : - 它给出不为零的分钟。如果分钟在 1 到 9 之间。
例如:我的设备上有时间 12:09 但它显示为 12:9
cal.MINUTE : - 这是用于 Calendar 方法调用的静态最终整数。
并且从实例化对象调用 static 成员是不好的做法。
因此,通过 cal.get(Calendar.MINUTE);
获得正确值的最佳方法。