package org.kodejava.util;
import java.util.Calendar;
public class DayYearToDayMonth {
public static void main(String[] args) {
// Create an instance of calendar for the year 2017 and set the
// day to the 180 day of the year.
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2021);
cal.set(Calendar.DAY_OF_YEAR, 180);
// Print the date of the calendar.
System.out.println("Calendar date is: " + cal.getTime());
// To know what day in month of the calendar we can obtain the
// value by calling Calendar's instance get() method and pass
// the Calendar.DAY_OF_MONTH field.
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
// Print which month day is it in number.
System.out.println("Calendar day of month: " + dayOfMonth);
// To know what day in week of the calendar we can obtain the
// value by calling Calendar's instance get() method and pass
// the Calendar.DAY_OF_WEEK field.
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
// Print which week day is it in number.
System.out.println("Calendar day of week: " + dayOfWeek);
}
}
The result of our above example is.
Calendar date is: Tue Jun 29 08:14:06 CST 2021
Calendar day of month: 29
Calendar day of week: 3
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024