Search code examples
javadatelocale

Identifyng the date format


Consuming a webs service, which is returning date in a format that is not able to identify.

              <Date>1140711</Date>
              <Time>94255</Time>

Its in Century +yy+MM+dd format, if the date is 20140711 (yyyyMMdd) then it will be 1140711. So how can I convert these date like 1140711to 07/11/2014(MM/dd/yyyy)


Solution

  • Probably the only way this might make sense is as 114-07-11, as if a programmer had forgotten to add 1900 to the return value of year taken from a Date.

    So: July 11, 2014.

    Chances are, that this programmer also didn't add 1 to the month, so it might just as well mean

    Or: August 11, 2014.

    The time might be 09:42:55

    Later To convert the date by decomposing and adding 1900:

    String cmd = "1141126";
    int len = cmd.length();
    int day = Integer.parseInt( cmd.substring( len - 2 ) ); 
    int month = Integer.parseInt( cmd.substring( len - 4, len - 2 ) ); 
    int year = 1900 + Integer.parseInt( cmd.substring( 0, len - 4 ) ); 
    String mdc = month + "/" + day + "/" + year;