jodatimejoda-convert

How can i format joda DateTime in this style "yyMMddHHmmss"?


i tried doing this:

    DateTime dt=new DataTime(DatetimeZone.UTC);
    DateTimeFormatter diff=DatTimeFormat.forPattern("yyMMddHHmmss");
    DateTime jtime=diff.ParseDateTime(dt.toString());

But am getting illegal argument exception. please help me to resolve this thanks in advance.


Solution

  • Try like this;

        DateTime today = new DateTime().withZone(DateTimeZone.UTC);
        System.out.println(today.toString(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z")));
    

    or this;

        DateTime dt = new DateTime(DateTimeZone.UTC);
        DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
        String str = fmt.print(dt);
        System.out.println(str);
    

    Also from JODA Javadoc; toString() method for DateTime outputs the date in ISO8601.