- 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
Get the days remaining in current year in Java
To get the days remaining in the current year, find the difference between the total days in the current year with the total number of days passed.
First, calculate the day of year.
Calendar calOne = Calendar.getInstance(); int dayOfYear = calOne.get(Calendar.DAY_OF_YEAR);
Now, calculate the total days in the current year 2018.
int year = calOne.get(Calendar.YEAR); Calendar calTwo = new GregorianCalendar(year, 11, 31); int day = calTwo.get(Calendar.DAY_OF_YEAR); System.out.println("Days in current year: "+day);
The following is the final example that finds the difference between the above two to get the days remaining in the current year.
Example
import java.util.Calendar; import java.util.GregorianCalendar; public class Demo { public static void main(String args[]) { Calendar calOne = Calendar.getInstance(); int dayOfYear = calOne.get(Calendar.DAY_OF_YEAR); int year = calOne.get(Calendar.YEAR); Calendar calTwo = new GregorianCalendar(year, 11, 31); int day = calTwo.get(Calendar.DAY_OF_YEAR); System.out.println("Days in current year: "+day); int total_days = day - dayOfYear; System.out.println("Total " + total_days + " days remaining in current year"); } }
Output
Days in current year: 365 Total 38 days remaining in current year
- Related Articles
- How to get the current year in JavaScript?
- How to get current day, month and year in Java 8?
- Days till End of Year in Java
- Get current year in MySQL WHERE clause?
- Java Program to get current date, year and month
- How to get the only current year in JavaScript?
- How to check Leap Year in Java 8 How to get current timestamp in Java 8?
- Java Program to get date for all the days of the current week
- Get elapsed time in days in Java
- Get current thread in Java
- Subtract days from current date using Calendar.DATE in Java
- Get the Current Working Directory in Java
- Get current time information in Java
- How to get the current date in Java?
- Get the number of days between current date and date field?

Advertisements