我想在如果else语句来测试上午或下午..如何测试上午或下午?
if(am){
//Do something
else{
//Do something else
我用尽
int am = cld.get(Calendar.AM_PM);
但如果其他
不会把它作为一个参数测试。也许是因为它不是布尔值。
我该如何去测试呢?
我想在如果else语句来测试上午或下午..如何测试上午或下午?
if(am){
//Do something
else{
//Do something else
我用尽
int am = cld.get(Calendar.AM_PM);
但如果其他
不会把它作为一个参数测试。也许是因为它不是布尔值。
我该如何去测试呢?
你是正确的if-else不会接受它,因为它不是布尔值。 Calendar.AM_PM
只能保存值0
或1
。像C这样的语言会接受0或1作为布尔值; Java不会。
你想要做更多的东西是这样的:
int am = cld.get(Calendar.AM_PM);
if (am == 0) {
// Do whatever for the AM
} else {
// Do whatever because it must be PM
}
当然,你的if子句不能接受整数,因为它是。你需要一些东西(比较可能)来获取布尔值。
if(am > 0)
{
//its PM
else { //its AM }
Calendar.AM_PM
是一个int。要在if
语句中对其进行评估,请将其转换为布尔值:
if((bool)am) {
//It's AM
} else {
//It's PM
}
whats the 0 mean?它与我的比较是什么? –
http://developer.android.com/reference/java/util/Calendar.html#AM 这就是为什么0,AM常数值为0。 –