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 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);/*from ww w. j a v a 2 s . c om*/ 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);//from ww w .ja v a2 s . c om System.out.println("date after one year : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }
From source file:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(2001, 1, 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)); 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)); 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:MainClass.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, Calendar.DECEMBER); }
From source file:Main.java
public static void main(String args[]) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal2.add(Calendar.HOUR, 2);/*from w w w . j a v a 2s . co m*/ cal2.add(Calendar.MINUTE, 42); cal2.add(Calendar.SECOND, 12); long secs = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 1000; String display = String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, (secs % 60)); System.out.println(display); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get what the minimal days required in the first week of the year int i = cal.getMinimalDaysInFirstWeek(); // print the result System.out.println("Minimal days required :" + i); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); 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_MONTH, 1); 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[] 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 ww w .j a va 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)); }