• Register
1 vote
23 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

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 178 views
178 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
2 votes
1 answer 16 views
16 views
Problem: I just started learning java and solving problems from various online websites. Stuck on a problem saying, count how many times a substring appears in a string java. This problem is beyond my understanding. I found Kodlogs very helpful and friendly environment ... possible solution (with code snippet) would be great for me, and I must recognize your help. Thanks in advance, mate.
asked Mar 25 Gavin 15.3k points
0 votes
2 answers 76 views
76 views
Problem : I want to compile a project in Eclipse using the m2eclipse. I set my JDK path in Eclipse as below: Windows-->preferences-->installed jres--> jdk1.7.xx path But this is showing me below error [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ ... BUILD FAILURE [INFO] ------------------------------------------------------------------------
asked Feb 4 jwilliam 3.9k points
0 votes
1 answer 111 views
111 views
Problem : I am trying to print every string in Reverse Double Character way (e.g. string -> ggnniirrttss) import java.util.Scanner; public class ReverseDoubleCharecters { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter ... I get as follows: ss tt rr ii nn gg All double characters are printed on new lines. Anybody has the solution on this?
asked Nov 22, 2019 peterlaw 6.9k points
1 vote
1 answer 31 views
31 views
Problem: I am new in python programming language and I have been doing a online python course. I am doing my coding practice. I tried to check out in a string how many time word does exist or appear. I wrote this code to check this thing: test = "If you do not ... 3 Appearence = test.count("do" 0, 100) ^ SyntaxError: invalid syntax Can anyone help me out to solve this thing. Thank you in advance.
asked Apr 7 LizzyM 6.1k points