java - Comparison between two dates not showing correct result -


in android app, need find date greater or smaller.i have used following code.this code works shows wrong output.pls help

    string strdate1 = "3/9/2013";        string strdate2 = "4/6/2013";         simpledateformat sdf = new simpledateformat( "m/d/yyyy" );        java.util.date d1;     java.util.date d2;     try {         d1 = sdf.parse( strdate1 );         d2 = sdf.parse( strdate2 );            if  ( d1.after(d2))           {                  system.out.println( "d1 after d2" );          }            else if  ( d1.before(d2) )         {                system.out.println( "d1 before d2" );          }            else           {               system.out.println( "d1 equal d2" );            }        } catch (parseexception e) {         // todo auto-generated catch block         e.printstacktrace();     }    

for above code got output "d1 after d2".but real thing "d1 before d2".pls suggest if did mistake on this.

you used wrong format month.

simpledateformat sdf = new simpledateformat( "m/d/yyyy" ); 

m minutes in hours m month in year


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -