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)); 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 time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); now.add(Calendar.SECOND, 100); System.out.println("New time after adding 100 seconds : " + 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 time : " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND)); now.add(Calendar.MINUTE, 20); System.out.println("New time after adding 20 minutes : " + 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 cal = Calendar.getInstance(); System.out.println("Now : " + cal.getTime()); int monthsToDecrement = -1; cal.add(Calendar.MONTH, monthsToDecrement); System.out.println("Date after decrement: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); // get the value of all the calendar date fields. System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR)); System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH)); System.out.println("Calendar's Day: " + cal.get(Calendar.DATE)); }
From source file:MainClass.java
public static void main(String args[]) { Calendar dateTime = Calendar.getInstance(); System.out.printf("%1$tH:%1$tM:%1$tS\n", dateTime); System.out.printf("%1$tZ %1$tI:%1$tM:%1$tS", dateTime); }
From source file:Main.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); int lastDate = calendar.getActualMaximum(Calendar.DATE); System.out.println("Date : " + calendar.getTime()); System.out.println("Last Date: " + lastDate); }
From source file:Main.java
public static void main(String[] args) { Calendar future = Calendar.getInstance(); future.set(Calendar.YEAR, 3010); Calendar now = Calendar.getInstance(); System.out.println("Is futureCal after now ? : " + future.after(now)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); 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.SECOND, -50); System.out.println("Time before 50 minutes : " + 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)); 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)); }