Calendar.get()

Date

Calendar.get(field) Collect field value
field: Required fields of Calendar like YEAR, MONTH, DAY_OF_MONTH, HOUR, MINUTE, SECOND etc

Examples with output
Let us create one calendar object and collect different field values from it . Output is given against each line.
One date object is created by using set() by using inputs Year, Month, Date, Hour, Minute, Second.
package my_proj;
import java.util.Calendar; 
public class my_first {
public static void main(String[] args) {
    
Calendar my_cal = Calendar.getInstance();// created calendar 
//Year, Month, Date, Hour, Minute, Second
my_cal.set(2020, 5, 25,22,59,45);


System.out.println(my_cal.get(Calendar.YEAR)); //  2020
System.out.println(my_cal.get(Calendar.MONTH)); // 5
System.out.println(my_cal.get(Calendar.ERA)); //1
System.out.println(my_cal.get(Calendar.WEEK_OF_YEAR)); // 26
System.out.println(my_cal.get(Calendar.WEEK_OF_MONTH)); // 4
System.out.println(my_cal.get(Calendar.DATE)); // 25
System.out.println(my_cal.get(Calendar.DAY_OF_MONTH)); // 25
System.out.println(my_cal.get(Calendar.DAY_OF_YEAR)); // 177
System.out.println(my_cal.get(Calendar.DAY_OF_WEEK)); // 5
System.out.println(my_cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)); // 4
System.out.println(my_cal.get(Calendar.AM_PM)); // 1
System.out.println(my_cal.get(Calendar.HOUR)); // 10
System.out.println(my_cal.get(Calendar.HOUR_OF_DAY)); // 22
System.out.println(my_cal.get(Calendar.MINUTE)); // 59
System.out.println(my_cal.get(Calendar.SECOND)); // 45
System.out.println(my_cal.get(Calendar.MILLISECOND)); // 393
System.out.println(my_cal.get(Calendar.ZONE_OFFSET)); // 19800000
System.out.println(my_cal.get(Calendar.DST_OFFSET)); // 0
System.out.println(my_cal.get(Calendar.SUNDAY)); // 2020
System.out.println(my_cal.get(Calendar.MONDAY)); // 5
System.out.println(my_cal.get(Calendar.TUESDAY)); // 26
System.out.println(my_cal.get(Calendar.JANUARY)); // 1
System.out.println(my_cal.get(Calendar.AM)); // 1
}
}
clear() Date & time tutorials



plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer