0

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.

Karthik Suresh
  • 367
  • 7
  • 23

2 Answers2

1

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.

Semih Eker
  • 2,389
  • 1
  • 20
  • 29
0

I tried a lot and came up with this solution

dt.toString("yyMMddHHmmss");
Karthik Suresh
  • 367
  • 7
  • 23