1. date.getDay () returns the day of the week. sunday is 0 and similarly saturday is 6. Please see the java docs. As per the comment given below. Calendar cal = Calendar.getInstance (); int dayOfMonth = cal.get (Calendar.DAY_OF_MONTH); String dayOfMonthStr = String.valueOf (dayOfMonth); System.out.println (dayOfMonthStr); Share. Assuming that you cannot use Java 8, here is how it could be done: SimpleDateFormat df = new SimpleDateFormat ("MM/dd/yyyy"); // Create first day of year Calendar firstDayOfCurrentYear = Calendar.getInstance (); firstDayOfCurrentYear.set (Calendar.DATE, 1); firstDayOfCurrentYear.set (Calendar.MONTH, 0); System.out.println (df.format Java 8 introduces a new DateTime API for manipulating date and time. The API provides many Java classes. But one of the most useful class in this API is the LocalDate class, for holding a date value. It belongs to java.time package. In the following Java program, we have used the parse() method of the LocalDate class. Learn about how to get number of days in Month in java. Get number of days in Month in java Using YearMonth’s lengthOfMonth() [Java 8] You can use YearMonth‘s lengthOfMonth() method to get number of days in Month in java. Pass Year and month to YearMonth’s of and create YearMonth object. Call lengthOfMonth() on YearMonth’s object to get The default constructor will initialize the calendar with the current date and time in the time zone and locale of the operating system: new GregorianCalendar(); We can specify the year, month, dayOfMonth, hourOfDay, minute, and second for the default time zone with the default locale: new GregorianCalendar(2018, 6, 27, 16, 16, 47); Use LocalDate and DateTimeFormatter from java.time, the modern Java date and time API. Second, I recommend you keep data model and presentation separate. Which day it is belongs in the model and is nicely represented by a LocalDate. For presentation convert the LocalDate back to a string to the user’s liking, for example Apr 1, 2019. APkTn.

java day of year