I have a string that is in the form of MMM / dd / yyyy I / 21 / May 2010. Now I want to convert it to yyyyMMdd, ie, 20100521.
My code is:
public static zero main (string [] args) {ArrayList & lt; String & gt; Date = new archilist & lt; String & gt; (); Dates.add ("Jan / 13/2011"); Dates.add ("February / 03/2001"); Dates.add ("March / 19/2012"); Dates.add ("April / 20/2011"); Dates.add ("May / 21/2010"); Dates.add ("June / 23/2008"); Dates.add ("Jul / 12/2009"); Dates.add ("August / 14/2010"); Dates.add ("Sep / 01/2011"); Dates.add ("Oct / 07/2010"); Dates.add ("Nov / 05/2011"); Dates.add ("Dec / 30/2011"); For (strings: dates) {System.out.println (Transformer date (s)); }} and the method for conversion:
public string transform parayet (string daoto) {string [] splitter = datoe.split ("/" ); String M = Splitter [0]. Toucherace (); String D = splitter [1]; String Y = Diffeter [2]; Date format format = new SimpleDateform ("MMM"); Date format format 2 = new simpledate format ("MM"); Try {Date date = formatter.parse (m); M = Formater 2 Format (date); } Hold (ParseException e) {e.printStackTrace (); } String date = y + m + d; return date; } The problem is that I get an unparseable date exception, May and October I'm from Denmark and if I change it to "Major" and "OKT" to Danish it Success is on. So what am I doing wrong here?
After adding text to "itemprop =" text ">
location , Use Locale.ENGLISH ). Better solution:.
public string transformPrevDate (string datoe) {SimpleDateFormat DateFormat = New SimpleDateform ("MMM / DD / Yay", Locale.GGLIISH); SimpleDataformatetformformat 2 = New SimpleDetermat ("YyamMed"); Try {return dateFormat2.format (dateFormat.parse (datoe)); } Grip (ParseException E) {// TODO self generated blocking block e.printStackTrace (); }}
Comments
Post a Comment