this is the code which returns Date but at the client side i am getting
2016-12-26 14:18:57.0 at the client side . what is the possible solution .. I am using node.js at the client side. But I think it has nothing to do with this problem . I WANT TO REMOVE THIS 0
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date date = sdf.parse(value);
if (!value.equals(sdf.format(date))) {
date = null;
}
return date != null;
tl;dr
Avoid legacy date-time classes
You are using troublesome old date-time classes, now legacy, supplanted by the java.time classes.
ISO 8601
First replace the SPACE in the middle of your input string to make it comply with the standard ISO 8601 format.
LocalDateTime
Parse as a
LocalDateTime
given that your input string lacks any indication of offset-from-UTC or time zone.Generate a String by simply calling
toString
. By default an ISO 8601 format is used to create the String. If the value has no fractional second, no decimal mark nor any fractional seconds digits appear.If you dislike the
T
in the middle, replace with a SPACE.If your input might carry a fractional second and you want to delete that portion of data entirely rather than merely suppress its display, truncate the
LocalDateTime
object.About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as
java.util.Date
,Calendar
, &SimpleDateFormat
.The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as
Interval
,YearWeek
,YearQuarter
, and more.