I have a string
String time = "2012-09-12 15:04:01";
I want to parse that string to Joda-Time:
DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime time = dateStringFormat.parseDateTime(date);
But when I print time
time.toString()
The output is:
2012-09-12T15:04:01.000+03:00
Why output is different from input? What I do wrong? I mean what is 'T'?? Thanks in advance.
I think you want...
dateStringFormat.print(time);
When you parse a date or number you extra its value, not the format it was as a String.
When you toString() the value is converts it to a default format.
Why output is different from input ?
It would be surprising coincidence if it were the same.
What I doing wrong?
Assuming there is only one format of a value.
I mean what is 'T' ?
It means it is in ISO 8601 format.
BTW you have the same problem with numbers
System.out.println(Double.parseDouble("123456789"));
System.out.println(Double.parseDouble("1.1e2"));
prints
1.23456789E8
110.0
In each case the value is correct, but original format is not recorded or preserved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With