I get Date as java.util.Date(not String) : (java.util.Date) Mon Jul 13 00:00:00 IST 2020
I want to convert it to : 2020-07-13T00:00 format==>("yyyy-MM-dd'T'HH:mm") but as DATE not String.
I tried following code:
Date scheduleDate=details.getScheduledDate(); // This value is fetched from object passed-- [scheduleDate = (java.util.Date) Mon Jul 13 00:00:00 IST 2020]
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
sd.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
String dateFormat=sd.format(scheduleDate); //Here I get [dateFormat = (java.lang.String) "2020-07-13T00:00"]
Date date = sd.parse(dateFormat); //[date = (java.util.Date) Mon Jul 13 00:00:00 IST 2020]
I observed that string format has correct(as expected ) value but the value changes back when I convert it to java.util.date.
Does java.util.Date support yyyy-MM-dd'T'HH:mm format ?
If yes, Can anyone suggest me with any good approach/direction/topics/library to look into.
Thank You..
java.util.Dateitself does not hold any information about formatting. You can't set format of it. You can set format only when you want to display it, aka convert to String. Btw. You probably should move to a "new" Java Date/Time API that was added in java 8 (in package java.time)Z), and then do your formatting on the client side. The default JS library for this seems to be Moment.