Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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
Java Android中calendar.MINUTE和calendar.get(calendar.MINUTE)之间的差异_Java_Android_Calendar - Fatal编程技术网

Java Android中calendar.MINUTE和calendar.get(calendar.MINUTE)之间的差异

Java Android中calendar.MINUTE和calendar.get(calendar.MINUTE)之间的差异,java,android,calendar,Java,Android,Calendar,我有两个Calendar变量,分别命名为calendar1和calendar2 其中存储了一些日历值 我想比较这些变量的MINUTE值 我发现了两种方法,但我想知道它们的区别是什么,哪一种是正确的 if(calendar1.MINUTE == calendar2.MINUTE) 及 非常感谢。MINUTE以整数形式返回分钟数:例如(13:04->MINUTE is 4) get(int-field)->首先调用complete()计算字段值,然后返回给定字段的值 complete()->如果尚

我有两个
Calendar
变量,分别命名为
calendar1
calendar2
其中存储了一些日历值

我想比较这些变量的
MINUTE

我发现了两种方法,但我想知道它们的区别是什么,哪一种是正确的

if(calendar1.MINUTE == calendar2.MINUTE)


非常感谢。

MINUTE
以整数形式返回分钟数:例如(13:04->MINUTE is 4)

get(int-field)
->首先调用
complete()
计算字段值,然后返回给定字段的值


complete()
->如果尚未设置时间,则从字段计算时间

calendar1.MINUTE
表示您正在访问
Calendar
类的
static
常量之一。这与日历分钟相同

不应使用对象(例如calendar1.MINUTE)访问常量字段

调用
calendar1.get()
时,需要传递要检索的日历字段,可以是
MINUTE
HOUR
毫秒
YEAR
MONTH
DAY\u/u\u\u\u\u/code>

关于这条线

if(calendar1.MINUTE == calendar2.MINUTE)
您只是比较这两个常量,它将始终返回
true

第二行是正确的

if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))

好的,这是你问题的答案

Calender.MINUTE:-它给出不带零的分钟数。如果分钟数在1到9之间

e、 g:我的手机12:09有时间,但它给出的时间是12:9

cal.MINUTE:-这是一个静态的最终整数,用于日历方法调用

从实例化对象调用静态成员是一种不好的做法


所以,通过
cal.get(Calendar.MINUTE)获得正确值的最佳方法

在何时以及为什么要使用哪一个?您应该将第二个与get()一起使用;因为分钟是静态的最终整数;从实例化对象调用静态成员是一种不好的做法。这是我一直在寻找的答案。但是,如果calendar.MINUTE总是返回相同的值(作为一个静态字段),它的意义是什么呢?只需使用calendar.MINUTE即可。@SteveBenett我这样做了,但它没有按预期工作。即使分钟数不相同,
if
仍返回
true
。(编辑)我想返回时不带零并不是唯一的区别。Gleen的ans是正确的。“它总是回到真的。”斯鲁扬巴拉伊:他的回答非常正确+给他一个。
if(calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE))