Java Program to Convert Days to Seconds

This article contains a program in Java to convert given number of days into seconds. There are 86400 seconds in a day.

The question is, write a Java program to convert days into seconds. The days must be received by user at run-time. The program given below is answer to this question.

import java.util.Scanner;

public class CodesCracker
   public static void main(String[] args)
      int noOfDays, noOfSeconds;
      Scanner s = new Scanner(;
      System.out.print("Enter the Number of Days: ");
      noOfDays = s.nextInt();
      noOfSeconds = noOfDays*86400;
      System.out.println("\nTotal Seconds = " +noOfSeconds);

Here is its sample run with user input 12 as number of days to convert or find and print the total number of seconds passed in given 12 days:

java convert days to seconds

This type of Java program comes under the category of simplest program, as here, we only need to receive the input from user and then multiply with 86400. The result will be the total number of seconds in given number of days. So we only need to print the result value on output. That's it.

To make the above program more shorter, then replace all the statements present inside the main() method, with these statements:

Scanner s = new Scanner(;
System.out.print("Enter the Number of Days: ");
int noOfDays = s.nextInt();
System.out.println("\nTotal Seconds = " +noOfDays*86400);

The output will exactly be same as of previous program.

Java Online Test

« Previous Program Next Program »

Follow/Like Us on Facebook

Subscribe Us on YouTube