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:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println("Current full date time is : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND)); }
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 = Calendar.getInstance(); now.add(Calendar.WEEK_OF_YEAR, -50); System.out.println("date before 50 weeks : " + (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 calendar = Calendar.getInstance(); // 15-04-2012 calendar.set(Calendar.DAY_OF_MONTH, 15); calendar.set(Calendar.YEAR, 2012); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MONTH, 3); Date start = calendar.getTime(); // 15-06-2012 calendar.set(Calendar.MONTH, 5); Date end = calendar.getTime(); calendar.setTime(start);//w w w. j a v a 2s .c om Date d = null; while ((d = calendar.getTime()).before(end) || d.equals(end)) { int day = calendar.get(Calendar.DAY_OF_WEEK); if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) { System.out.println(d); } calendar.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:MainClass.java
public static void main(String[] args) { // get a calendar using the default time zone and locale. Calendar calendar = Calendar.getInstance(); // set Date portion to January 1, 1970 calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DATE, 1); // normalize the object calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); }
From source file:Main.java
public static void main(String... args) { SimpleDateFormat df = new SimpleDateFormat("MM/dd/YYYY"); Calendar c = Calendar.getInstance(); System.out.println(df.format(c.getTime())); c.add(Calendar.YEAR, 60); System.out.println(df.format(c.getTime())); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar future = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); future.set(Calendar.YEAR, 2015); System.out.println("Year is " + future.get(Calendar.YEAR)); Date time = future.getTime(); if (future.after(cal)) { System.out.println("Date " + time + " is after current date."); }/*from w w w . jav a2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { // create a calendar Calendar cal = new GregorianCalendar(2010, 9, 15); // print the greatest min. for year field int result = cal.getGreatestMinimum(Calendar.YEAR); System.out.println("The minimum is: " + result); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Calendar past = Calendar.getInstance(); System.out.println("Current date: " + cal.getTime()); // change year in past calendar past.set(Calendar.YEAR, 2013); System.out.println("Year is " + past.get(Calendar.YEAR)); // check if calendar date is before current date System.out.println(cal.before(past)); }
From source file:Main.java
public static void main(String[] args) { int dayOfWeek = Calendar.SUNDAY; Calendar cal = new GregorianCalendar(); cal.set(2015, 0, 1, 0, 0);/* w ww. ja v a 2 s .c o m*/ cal.set(Calendar.DAY_OF_WEEK, dayOfWeek); while (cal.get(Calendar.YEAR) == 2015) { System.out.println(cal.getTime()); cal.add(Calendar.DAY_OF_MONTH, 7); } }
From source file:MainClass.java
public static void main(String args[]) { GregorianCalendar gc = new GregorianCalendar(); int year = gc.get(Calendar.YEAR); System.out.println(year);//from w ww .j av a 2s .c o m System.out.println(gc.isLeapYear(year)); System.out.println("Month = " + gc.get(Calendar.MONTH)); System.out.println("Week of year = " + gc.get(Calendar.WEEK_OF_YEAR)); System.out.println("Week of month = " + gc.get(Calendar.WEEK_OF_MONTH)); System.out.println("Day of year = " + gc.get(Calendar.DAY_OF_YEAR)); System.out.println("Day of week = " + gc.get(Calendar.DAY_OF_WEEK)); }