简体   繁体   中英

Joda-Time: parse string

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.

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.

我想你想......

dateStringFormat.print(time);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM