java - Compare disparate Date formats, which are stored as Strings -
i have 2 disparate date formats presented in application strings. here formats:
- 07/01/2011
- 2011-07-01
i'm looking efficient way assert equality.
parse both dates using simpledateformat
, use equals()
method.
the formats use "mm/dd/yyyy"
, "yyyy-mm-dd"
.
sample code:
simpledateformat format1 = new simpledateformat("mm/dd/yyyy"); simpledateformat format2 = new simpledateformat("yyyy-mm-dd"); date date1 = format1.parse(value1); date date2 = format2.parse(value2); return date1.equals(date2);
Comments
Post a Comment