I do not see a problem with the example below. For some reason, it seems to ignore the year and say that the dates are the same, as seen in the output below. I have to miss something simple.
01/28/2006 01/16/2007 Tue Apr 01 00:00:00 PDT 2008 Tue Apr 01 00:00:00 PDT 2008 done
import java.util.*; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; class ExampleProgram { public static void main(String[] args){ DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String d1String = "01/28/2006"; String d2String = "01/16/2007"; System.out.println(d1String); System.out.println(d2String); Date d1=null; try { d1 = df.parse(d1String); } catch (ParseException e) { System.out.println(e.getMessage()); } Date d2=null; try { d2 = df.parse(d2String); } catch (ParseException e) { System.out.println(e.getMessage()); } System.out.println(d1); System.out.println(d2); System.out.println("done"); } }
"dd/MM/yyyy"
should read:
"MM/dd/yyyy"
as Peter mentioned, the meaning of the letters can be found in the documentation: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
, , , , , SimpleDateFormat "MM/dd/yyyy", , , , , "dd/MM/yyyy", d1String - 28. 28 - 12, , 16 - 12, , - 4 (), - 2008 . d2String.
SimpleDateFormat
d1String
d2String
Date.
Source: https://habr.com/ru/post/1706368/More articles:Auto Pointer in VC2008 - copy-constructorglDrawPixels in grayscale? - c ++Using deferred execution using javascript - javascriptHow to create a screenshot of Flash SWF on a server? - flashHow do you use display specifications? - x11Java screen capture application - javaCheckbox PHP form and undefined index - phpAuto Generation Objects - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1706372/mapping-uml-class-diagram-in-eclipse-modelling-tools-to-actual-classes&usg=ALkJrhgNXVSF1GSYqGDh6CoKUrVicI-gHAcss, javascript - where to start? - javascriptAll Articles