CopyPastehas never been so tasty!

Get Time from date in java

by anonymous

  • 0
  • 0
  • 0
69 views

Get Time from date in java

Get Time from Date in Java:In java if you want to Get time from date you have to use D ateFormat, ParseException and SimpleDateFormat. Make a class and pass a String, getTimefromDate is a method you will use, an exception will occur in some cases. Make a new object. “H” stands for hour, M stands for minutes and “S” stands for seconds.Here you have a simple code that will tell you how to get time from date in java: 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Util{
    public static String getTimeFromDate (Date date) throws ParseException

 {
       DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS");
      return formatter.format(date);


    }

}

 This is simple article that will tell you how to get Time from date in Java.

Add A Comment: