In this tutorial you will learn how can you change a time value into seconds.

## Java time to seconds Example

In this tutorial you will learn how can you change a time value into seconds.

Here I am giving a simple example for changing a time into seconds. In the example given below I have done some mathematical processes such as to change the hour into seconds multiplied the hour by 3600 because an hour is of 3600 sec., to change minute into second multiplied the minute by 60 because 1 minute = 60 sec.

Example :

```import java.util.*;

class TimeToSec
{
static int h;
static int m;
static int s;
public TimeToSec()
{
int h = 0;
int m = 0;
int s = 0;
}
public static void main(String arr[])
{
int sec;
System.out.println("Conversion of time value into second(s)");
System.out.println("Enter time value :");

Scanner scan = new Scanner(System.in);

System.out.println("Enter the value of hour : ");
h= scan.nextInt();
System.out.println("Enter the value of minute : ");
m = scan.nextInt();
System.out.println("Enter the value of second : ");
s = scan.nextInt();
sec = h*3600+m*60+s;
System.out.println("Time after calculating into second(s) : ");
System.out.println(sec);
}
}```

Output :

When you will execute the above example you will get the output as : Go to Topic «PreviousHomeNext»  