0

Date Util

public class DateUtil {

public static Date StringToDate(String date) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.ENGLISH);
Date convertedDate = null;
try {
  convertedDate = sdf.parse(date);
} catch (ParseException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}
return convertedDate;

}

}

The String Input when i call it

2018/06/08

The value it returns is

Fri Jun 08 00:00:00 CST 2018

  • *"A Java Date is a container for the number of milliseconds since January 1, 1970, 00:00:00 GMT"* - `Date` does not have any concept of "format", when you print the `Date`, the object is using a "human readable" format (based on you current configuration) to display the value for you. If you want to "display" the `Date` in a different format, you use a date formatter. Since it's 2018 now, you should be using the newer date/time API introduced in Java 8 (or the three ten back port if you're not using Java 8) – MadProgrammer Jun 18 '18 at 02:44
  • so that's why its returning that value,thanks for the info,,,i'll do that, –  Jun 18 '18 at 03:36

0 Answers0