Search code examples
javadatedate-formatsimpledateformat

Format particular date with T character


What is the correct form for parse this date?: 2015-05-29T00:00:00+02:00

DateFormat format = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss");
Date data = format.parse(dataValue);

Solution

  • Try with

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    

    Notice that

    • MM represents months, while mm represents minutes.
    • if you want to have 24h format use HH, hh is for 12h format
    • XXX represents time zone in format like -08:00
    • to add literal like T in format you need to surround it with single quotes ' like 'T'