

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Days till End of Year in Java
To get the days until the end of the year, find the difference between the total days in the current year with the total number of passed.
Firstly, calculate the day of the 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);
Find the difference and you will get the days until the end of the year.
The following is the complete example.
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); System.out.println("Current Year: "+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 "+year); } }
Output
Current Year: 2018 Days in current year: 365 Total 38 days remaining in 2018
- Related Questions & Answers
- Get the days remaining in current year in Java
- How to find the number of days in a month of a particular year in Java?
- How to scroll down the page till page end in the Selenium WebDriver?
- Enum for days of week in Java
- Get beginning and end date from a specific year in MySQL
- Java Program to Find Even Sum of Fibonacci Series till number N
- Display Month of Year using Java Calendar
- MySQL query to count days in date range with start and end date
- Why Kamakhya Temple of Guwahati is mysterious and remains completely closed for 4 days in a year?
- Convert day of year to day of month in Java
- Alternate Primes till N in C++?
- Display three-digit day of the year in Java
- Display four-digit year in Java
- Display two-digit year in Java
- Get elapsed time in days in Java
Advertisements