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 calendar = Calendar.getInstance(); int lastDate = calendar.getActualMaximum(Calendar.DATE); calendar.set(Calendar.DATE, lastDate); int lastDay = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Last Date: " + calendar.getTime()); System.out.println("Last Day : " + lastDay); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the days required in the first week of the year System.out.println("Months required: " + cal.get(Calendar.MONTH)); // print the lowest maximum months for year. int max = cal.getLeastMaximum(Calendar.MONTH); System.out.println("Lowest maximum months :" + max); }
From source file:MainClass.java
public static void main(String args[]) { Calendar dateTime = Calendar.getInstance(); System.out.printf("%1$tA, %1$tB %1$td, %1$tY\n", dateTime); System.out.printf("%1$TA, %1$TB %1$Td, %1$TY\n", dateTime); System.out.printf("%1$ta, %1$tb %1$te, %1$ty\n", dateTime); }
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 week of month is : " + now.get(Calendar.WEEK_OF_MONTH)); System.out.println("Current week of year is : " + now.get(Calendar.WEEK_OF_YEAR)); now.add(Calendar.WEEK_OF_YEAR, 1); System.out.println("date after one week : " + (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 cal = Calendar.getInstance(); System.out.printf("Current time and date: %tc\n", cal); }
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)); // add days to current date using Calendar.add method now.add(Calendar.DATE, 1);//w w w . jav a 2 s .co m System.out.println("date after one day : " + (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 cal = Calendar.getInstance(); // print current state of lenient boolean b = cal.isLenient(); System.out.println("Calendar is lenient :" + b); // change lenient state cal.setLenient(false);/*from w w w . j a v a2s . c o m*/ System.out.println("Lenient after setting :" + cal.isLenient()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal1 = Calendar.getInstance(); cal1.set(2015, 2, 27);//from w ww .j av a 2 s .c om Calendar cal2 = Calendar.getInstance(); cal2.set(2015, 8, 1); boolean valid = isSixMonthsAgo(cal1, cal2); System.out.println(valid); }
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);//from ww w . j ava2 s . c o m // print the result System.out.println("Altered year is :" + cal.getTime()); }
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);//from w w w . j a v a 2 s . co m // print the result System.out.println("Altered year is :" + cal.getTime()); }