Q:

Java program to get milliseconds from the specified date

belongs to collection: Java Date and Time Programs

0

Java program to get milliseconds from the specified date

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will get the milliseconds from a date in the specified format and print the result.

Program/Source Code:

The source code to get milliseconds from a specified date is given below. The given program is compiled and executed successfully.

// Java program to get milliseconds from 
// specified date

import java.util.*;
import java.text.SimpleDateFormat;

public class Main {
  public static void main(String[] args) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy");
    String dateString = "15-03-1993";

    try {
      Date dt = dateFormat.parse(dateString);
      System.out.println("Date in milliseconds: " + dt.getTime());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Output:

Date in milliseconds: 732153600000

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Date and Time Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to get a date from milliseconds using... >>
<< Java program to convert \'java.util.Date\...