- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
- Related Articles
- Format MySQL date and convert to year-month-day
- Finding day of week from date (day, month, year) in JavaScript
- How to convert year, month, and day of the month into a complete date in R?
- How to Convert Numbers to Year/Month/Day or Date in Excel?
- How to get day of month, day of year and day of week in android using offset date time API class?
- How to get current day, month and year in Java 8?
- How to get a Date from year, month and day in Java?
- Filter the records of current day, month and year in MySQL?
- Create date from day, month, year fields in MySQL?
- Fetch month, day, year, etc. from ISODate in MongoDB?
- Get the last day of month in Java
- Java Program to get day of week for the last day of each month in 2019
- Display two-digit day of the month in Java
- Display three-digit day of the year in Java
- Day of the Year in Python

Advertisements