總網頁瀏覽量

2017年2月2日 星期四

[JAVA] Calendar 類別

Oracle 文章寫這樣

Returns the value of the given calendar field. In lenient mode, all calendar fields are normalized. In non-lenient mode, all calendar fields are validated and this method throws an exception if any calendar fields have out-of-range values. The normalization and validation are handled by the complete() method, which process is calendar system dependent.

完全看不懂

所以自己測


import java.util.Calendar;

public class dataaaaa{
    public static void main(String args[]){
        Calendar ca = Calendar.getInstance();
        for(int i = 0 ; i <= 10 ; i++)
            System.out.println(i+": "+ca.get(i));
    }
}


output :

0: 1
1: 2017
2: 1
3: 5
4: 1
5: 3
6: 34
7: 6
8: 1
9: 0
10: 11


看不懂 ? 正常

ID  Value  Description
--  -----  -----------
 0      1  Era (BC/AD for Gregorian).
 1   2017  Year.年
 2      1  Month (zero-based).月(以0開始算)
 3      5  Week-of-year.(今年第幾個禮拜)
 4      1  Week-of-month.(這個月第個禮拜)
 5      3  Date/day-of-month.(這個月第幾天)
 6     34  Day-of-year.(今年第幾天)
 7      6  Day-of-week.(這禮拜第幾天)
 8      1  Day-of-week-in-month.(今天是這個月的第幾個禮拜)
 9      0  AM/PM selector.(上午0/下午1)
10     11  Hour.(幾點 時部分)
 
 
[1] https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#get(int) 
[2] http://stackoverflow.com/questions/6605471/what-does-object-calendar-do 

沒有留言:

張貼留言