首頁 >php教程 >php手册 >java判断是否为下午或上午

java判断是否为下午或上午

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-01 09:46:422090瀏覽
<code class="language-java">import org.junit.Test;
/**
 * 测试当前时间是否为下午或上午
 * @author pamgo
 *
 */
public class CalendarT {
    @Test
    public void testTodayPMorAM(){
        int i = Calendar.getInstance(Locale.US).get(Calendar.AM_PM);
        System.out.println(i == Calendar.PM ? "pm":"am");
    }
    @Test
    public void testTodayPMorAM2(){
        boolean isPM = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 12;
        System.out.println(isPM ? "YES":"NO");
    }
}</code>

 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn