CopyPastehas never been so tasty!

Convert date into string in java

by anonymous

  • 0
  • 0
  • 0
88 views

Convert date into string in java

Conversion of Date into String in Java:In java if you want to convert date into String you have to use DateFormat, ParseException and SimpleDateFormat. Make a class and pass a String,getStringFromDate is a method that you will use to get string from date. However, an exception will occur in some cases. Make a new object and use return type that will return date.Following is 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 getStringFromDate (Date date) throws ParseException 

{
        DateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss");
      return formatter.format (date);


    }

}

 

Add A Comment: