List of usage examples for java.util Calendar get
public int get(int field)
From source file:MainClass.java
public static void main(String args[]) { Calendar calendar1 = Calendar.getInstance(); int doy1 = calendar1.get(Calendar.DAY_OF_YEAR); int year = calendar1.get(Calendar.YEAR); Calendar calendar2 = new GregorianCalendar(year, 11, 31); int doy2 = calendar2.get(Calendar.DAY_OF_YEAR); int days = doy2 - doy1; System.out.println(days + " days remain in current year"); }
From source file:MainClass.java
public static void main(String args[]) { Calendar calendar = Calendar.getInstance(); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.HOUR)); System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); System.out.println(calendar.get(Calendar.MINUTE)); }
From source file:Main.java
public static void main(String args[]) { Calendar calendar1 = Calendar.getInstance(); int currentDayOfYear = calendar1.get(Calendar.DAY_OF_YEAR); int year = calendar1.get(Calendar.YEAR); Calendar calendar2 = new GregorianCalendar(year, 11, 31); int dayDecember31 = calendar2.get(Calendar.DAY_OF_YEAR); int days = dayDecember31 - currentDayOfYear; System.out.println(days + " days remain in current year"); }
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[] args) { String dayNames[] = new DateFormatSymbols().getWeekdays(); Calendar date2 = Calendar.getInstance(); System.out.println("Today is a " + dayNames[date2.get(Calendar.DAY_OF_WEEK)]); }
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 = Calendar.getInstance(); now.add(Calendar.MINUTE, -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)); now.add(Calendar.MONTH, 10);//from w ww . ja va 2 s . c o m System.out.println("date after 10 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 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 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)); }