Convert day of year to day of month in Java



Firstly, set the day of year using DAY_OF_YEAR constant.

Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2018); cal.set(Calendar.DAY_OF_YEAR, 320);

Now, get the day of month −

int res = cal.get(Calendar.DAY_OF_MONTH);

The following is an example −

Example

 Live Demo

import java.util.Calendar; public class Demo {    public static void main(String[] args) {       Calendar cal = Calendar.getInstance();       cal.set(Calendar.YEAR, 2018);       cal.set(Calendar.DAY_OF_YEAR, 320);       System.out.println("Date = " + cal.getTime());       int res = cal.get(Calendar.DAY_OF_MONTH);       System.out.println("Day of month = " + res);    } }

Output

Date = Fri Nov 16 07:54:55 UTC 2018 Day of month = 16
Updated on: 2020-06-29T04:41:41+05:30

639 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements