List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:Main.java
public static void main(String[] args) { int dayOfYear = 112; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, dayOfYear); System.out.println("Day of year " + dayOfYear + " = " + calendar.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2007); cal.set(Calendar.DAY_OF_YEAR, 180); System.out.println("Calendar date is: " + cal.getTime()); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Calendar day of month: " + dayOfMonth); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); System.out.println("Calendar day of week: " + dayOfWeek); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); System.out.println(now.get(Calendar.DAY_OF_YEAR)); }
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 calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2007); calendar.set(Calendar.DAY_OF_YEAR, 180); // See the full information of the calendar object. System.out.println(calendar.getTime().toString()); // Get the weekday and print it int weekday = calendar.get(Calendar.DAY_OF_WEEK); System.out.println("Weekday: " + weekday); }
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: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:MainClass.java
public static void main(String args[]) { GregorianCalendar today = new GregorianCalendar(); int todayMonth = today.get(Calendar.MONTH); int todayDayOfMonth = today.get(Calendar.DAY_OF_MONTH); int todayYear = today.get(Calendar.YEAR); int todayDayOfYear = today.get(Calendar.DAY_OF_YEAR); int numDays;//from w w w. j a v a 2 s . co m if (todayMonth == 11 && todayDayOfMonth > 25) { GregorianCalendar xmas = new GregorianCalendar(todayYear + 1, 11, 25); int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR); numDays = xmasDayOfYear + 31 - todayDayOfMonth; } else { GregorianCalendar xmas = new GregorianCalendar(todayYear, 11, 25); int xmasDayOfYear = xmas.get(Calendar.DAY_OF_YEAR); numDays = xmasDayOfYear - todayDayOfYear; } System.out.println("The number of days till Christmas is " + numDays); }
From source file:MainClass.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); GregorianCalendar gc = new GregorianCalendar(); java.util.Date d = sdf.parse("12/12/2003"); gc.setTime(d);/* w w w . j a va2 s . c o m*/ System.out.println("Input Date = " + sdf.format(d)); int dayBefore = gc.get(Calendar.DAY_OF_YEAR); gc.roll(Calendar.DAY_OF_YEAR, -1); int dayAfter = gc.get(Calendar.DAY_OF_YEAR); if (dayAfter > dayBefore) { gc.roll(Calendar.YEAR, -1); } gc.get(Calendar.DATE); java.util.Date yesterday = gc.getTime(); System.out.println("Yesterdays Date = " + sdf.format(yesterday)); }
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 w w.ja v a2 s. co 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)); }