java - Parser pattern for monthOfYear that is not zero-padded with no literal text separation -


is possible parse date 8302011 using jodatime? in less painful format, 8/30/2011, pattern mm/dd/yyyy.

what i've tried:

  • pattern mddyyyy
    • 8302011 -> cannot parse "8302011": value 83 monthofyear must in range [1,12]
    • 12302011 -> 2011-12-30t00:00:00.000z

fortunately, date not ambiguous day represented 2 digits. month, however, either 1 or 2 digits.

i realize simple enough pad zeros on left 8 characters, in case, unable that.

i know below different jodatime can try use simpledateformat parse date alternative one

import java.text.parseexception; import java.text.simpledateformat; import java.util.date;  /**  * created luan on 9/12/16.  */ public class datetimeformattest {     public simpledateformat simpledateformat = new simpledateformat("mddyyyy");     public simpledateformat simpledateformat2 = new simpledateformat("mm/dd/yyyy");      public date getdate(string source){         date date = null;         try {             date = simpledateformat.parse(source);         } catch (parseexception e) {             e.printstacktrace();         }          return date;     }     public string parsestringvalue(date date){         string result = "";         result = simpledateformat2.format(date);         return result;     }      public static void main(string[] args) {         datetimeformattest obj = new datetimeformattest();         date date = obj.getdate("8302011");         system.out.println(date);         string result = obj.parsestringvalue(date);         system.out.println(result);     } } 

output:

tue aug 30 00:00:00 ict 2011 08/30/2011 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -