Joda-Time: parsing line

I have a line

String time = "2012-09-12 15:04:01"; 

I want to parse this line on Joda-Time :

 DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime time = dateStringFormat.parseDateTime(date); 

But when I print time

 time.toString() 

Output:

 2012-09-12T15:04:01.000+03:00 

Why is the output different from the input? What am I doing wrong? I mean, what is a T? Thank you in advance.

+4
source share
2 answers

When you parse a date or number, you add its value, not the format that it was like a string.

When you toString (), the value converts it to the default format.

Why is the output different from the input?

It would be an amazing coincidence if it were the same.

What am I doing wrong?

Assuming that there is only one value format.

I mean, what is a 'T'?

This means that it is in ISO 8601 format .


By the way, 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, this value is true, but the original format is not recorded or saved.

+9
source

I think you want ...

 dateStringFormat.print(time); 
+1
source

All Articles