List of usage examples for java.util Calendar YEAR
int YEAR
To view the source code for java.util Calendar YEAR.
Click Source Link
get
and set
indicating the year. From source file:MainClass.java
public static void main(String[] a) { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); calendar.add(Calendar.YEAR, 14); // 14 years into the future System.out.println(calendar.get(Calendar.YEAR)); }
From source file:Main.java
public static void main(String[] args) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();//w w w. ja v a2 s. c om cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.util.Date utilDate = cal.getTime(); System.out.println(utilDate); }
From source file:Main.java
public static void main(String[] a) { GregorianCalendar today = new GregorianCalendar(); GregorianCalendar thisDate = new GregorianCalendar(); thisDate.set(Calendar.YEAR, 2000); if (thisDate.before(today)) { System.out.println("before"); }//from w w w. j a v a 2s. c om if (today.after(thisDate)) { System.out.println("after"); } }
From source file:Main.java
public static void main(String[] args) { int year = 2009; int month = 0; // January int date = 1; Calendar cal = Calendar.getInstance(); cal.clear();/*ww w.j a va2s. com*/ cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DATE, date); java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis()); System.out.println(sqlDate); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); int day = cal.get(Calendar.DATE); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int dow = cal.get(Calendar.DAY_OF_WEEK); int dom = cal.get(Calendar.DAY_OF_MONTH); int doy = cal.get(Calendar.DAY_OF_YEAR); System.out.println("Current Date: " + cal.getTime()); System.out.println("Day: " + day); System.out.println("Month: " + month); System.out.println("Year: " + year); System.out.println("Day of Week: " + dow); System.out.println("Day of Month: " + dom); System.out.println("Day of Year: " + doy); }
From source file:Main.java
public static void main(String[] args) { Date myDate;/* w ww . j a v a 2 s.c o m*/ Calendar cal = Calendar.getInstance(); cal.set(Calendar.MONTH, 9); cal.set(Calendar.DATE, 24); cal.set(Calendar.YEAR, 2013); cal.set(Calendar.HOUR, 13); cal.set(Calendar.MINUTE, 45); cal.set(Calendar.SECOND, 52); myDate = cal.getTime(); System.out.println(myDate); }
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 w w . j ava2s . c om 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 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 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)); }
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);// www.j a v a2s . co m System.out.println("date before 5 months : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR)); }