• Register
1 vote
28 views

Problem:

Hi fellas,

I am a very new student in java programming. I am just wondering if I can find milliseconds in a year by a java program.

Do you have any idea how to write such a program?

Thanks

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

You can easily find out the total milliseconds in a calendar year by multiplying them sequentially.

Let's see how we can do it:

private static final int MILLIS_IN_SECOND = 1000;
private static final int SECONDS_IN_MINUTE = 60;
private static final int MINUTES_IN_HOUR = 60;
private static final int HOURS_IN_DAY = 24;
private static final int DAYS_IN_YEAR = 365;

private static final long MILLISECONDS_IN_YEAR = (long) MILLIS_IN_SECOND * SECONDS_IN_MINUTE * MINUTES_IN_HOUR * HOURS_IN_DAY * DAYS_IN_YEAR;

You can also find out the millis by built-in the Calendar function in java. Right, this way:

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
int daysInYear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);

System.out.println(TimeUnit.DAYS.toMillis(daysInYear));

I hope this will help you.

13 9 6
94,240 points

Related questions

0 votes
2 answers 558 views
558 views
Problem : I want to convert the Milliseconds in the format of number of years months weeks and days. e.g. 10 months, 4 weeks and 5 days I have already tried in few ways but it is becoming as 7 days and 0 weeks. Please find below my code for your referance: int weeks = ... am trying the logic by adding 1 to number of days as if I have 23 hours it should be 1 day. Please give me the solution on it.
asked Dec 2, 2019 alecxe 7.5k points
0 votes
1 answer 1 view
1 view
Problem: Can some help explain why we say 52 weeks and not 53?
asked 8 hours ago ochena 480 points
0 votes
1 answer 1 view
1 view
Problem: I need some details regarding,"how many weeks are there in a calendar year?"
asked 18 hours ago sumaiya simi 8.4k points
0 votes
1 answer 1 view
1 view
Problem: Can anyone suggest a solution,"how many weeks are in a year 2015?"
asked 19 hours ago sumaiya simi 8.4k points
0 votes
1 answer 5 views
5 views
Problem: I am stuck during learning as I have already mentioned in my question someone please cooperate me to continue my project-Thanks
asked Mar 22 sadi1982 36.3k points
0 votes
1 answer 1 view
1 view
Problem: I need some details regarding,"how many weeks are there in 1 year?"
asked 19 hours ago sumaiya simi 8.4k points
0 votes
1 answer 2 views
2 views
Problem: I need help in resolving this problem In a year, at most, how many months have five Sundays?
asked 5 days ago tuhin1 47.2k points
0 votes
1 answer 2 views
2 views
Problem: I'm having problems during my learning as I mentioned in my question above, I try to find on web search but I can't get proper information, can you help me to continue my project?
asked Mar 23 shamimkhan 15.1k points
0 votes
1 answer 3 views
3 views
Problem: Need your help to solve this >'how many weeks left in the year 2018' ?
asked Mar 20 Samiur1 38.4k points
0 votes
1 answer 26 views