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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -