How to Convert Hours to Seconds in Java
Java is a high level, object-oriented programming language. It supports creation of programs that can run on servers that host websites, create user interfaces and perform simple calculations. The instructions to convert hours to seconds in Java use integral variable types like integer (int), long and the multiplication operation.
Things You'll Need
- Java development kit
- Java program
- Java Integrated Development Environment (IDE)
Instructions
-
-
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.
-
1
Tips & Warnings
Choose "int" or "long" data type for holding the values depending on the maximum value required by your program. The data type "long" holds a larger value (9,223,372,036,854,775,807) compared to "int" (2,147,483,647).
References
Resources
- Photo Credit ruler with multiplication table image by Stepanov from Fotolia.com