java - Compare disparate Date formats, which are stored as Strings -


i have 2 disparate date formats presented in application strings. here formats:

  1. 07/01/2011
  2. 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

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -