How to Convert Hours to Seconds in Java
- 1). Open the Java program that needs to convert hours to seconds in the IDE for editing.
- 2). Assign the number of hours to an integer variable in the method that requires the hours-to-seconds conversion. For example: int hours = 7;
- 3). Multiply the variable holding number of hours by 3600. Multiplying by 60 converts it to number of minutes in the number hours and multiplying the minutes by another 60 converts it to seconds in the number hours. Multiplying 60 by 60 equals 3600 and converts hours to seconds.
- 4). Assign the multiplied value to a long variable. For example: long seconds = hours * 3600;
The variable seconds will now hold the value of hours in seconds.