List of usage examples for java.util Calendar get
public int get(int field)
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); String[] strDays = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thusday", "Friday", "Saturday" }; // Day_OF_WEEK starts from 1 while array index starts from 0 System.out.println("Current day is : " + strDays[now.get(Calendar.DAY_OF_WEEK) - 1]); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); System.out.println("New date after adding 10 hours : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); now = Calendar.getInstance(); now.add(Calendar.MONTH, -5);//w ww.j av a 2 s . co m System.out.println("date before 5 months : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); now.add(Calendar.YEAR, 1);/* www .j a v a2 s. c o m*/ System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25); int dayOfWeek = xmas.get(Calendar.DAY_OF_WEEK); // 6=Friday Calendar cal = new GregorianCalendar(2003, Calendar.JANUARY, 1); dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 4=Wednesday }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); now = Calendar.getInstance(); now.add(Calendar.YEAR, -100); System.out.println("date before 100 years : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); now.add(Calendar.HOUR, 10);/*from w w w . j av a 2 s. c o m*/ System.out.println("New time after adding 10 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); String[] strMonths = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; System.out.println("Current month is : " + strMonths[now.get(Calendar.MONTH)]); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current Date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); now = Calendar.getInstance(); now.add(Calendar.HOUR, -3);/* w w w. j a v a 2 s .c om*/ System.out.println("Time before 3 hours : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current date : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); now = Calendar.getInstance(); now.add(Calendar.DATE, -10);/*from w ww . ja v a 2 s. co m*/ System.out.println("date before 10 days : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }