List of usage examples for java.util Calendar getInstance
public static Calendar getInstance()
From source file:Main.java
public static void main(String[] args) { Calendar futureCal = Calendar.getInstance(); futureCal.set(Calendar.YEAR, 3000); 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("Is futureCal after now ? : " + futureCal.after(now)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Calendar cal = Calendar.getInstance(); int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28 }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Now : " + cal.getTime()); int daysToIncrement = 5; cal.add(Calendar.DATE, daysToIncrement); System.out.println("Date after increment: " + cal.getTime()); }
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);//from www. j av 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 www .j av a 2s . c o m System.out.println("date before 10 days : " + (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(); // add seconds to current date now.add(Calendar.SECOND, 500); System.out.println("adding 500 seconds : "); System.out.println(now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); // adding minus value now = Calendar.getInstance(); now.add(Calendar.SECOND, -500); System.out.println("adding -500 seconds: "); System.out.println(now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the maximum value that year field can have int i = cal.getActualMaximum(Calendar.YEAR); System.out.println("Maximum year:" + i); // get the maximum value that month field can have int a = cal.getActualMaximum(Calendar.MONTH); System.out.println("Maximum month:" + a); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // return the maximum value for days int max = cal.getMaximum(Calendar.DAY_OF_WEEK); System.out.println("Maximum days :" + max); // return the maximum value for months max = cal.getMaximum(Calendar.MONTH); System.out.println("Maximum months :" + max); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // return the minimum value that the year field could have int i = cal.getActualMinimum(Calendar.YEAR); System.out.println("Minimum Year :" + i); // returns the minimum value that the month field could have int a = cal.getActualMinimum(Calendar.MONTH); System.out.println("Minimum month :" + a); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // print current time System.out.println("Current year is :" + cal.getTime()); // set the year,month and day to something else cal.set(2013, 5, 25, 04, 15, 20);//from w w w . ja va2 s. co m System.out.println("Altered year is :" + cal.getTime()); }