Incompatibility between JodaTime and JavaTime

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Incompatibility between JodaTime and JavaTime

Wojtek K
Hi All,

Is there a difference between DateTimeFormatter and SimpleDateFormat  
in respect of parsing milliseconds?  This is my test code:

String pattern = "yyyyMMddHHmmssSS";

SimpleDateFormat javaDateFormatter = new SimpleDateFormat(pattern);
DateTimeFormatter jodaDateFormatter = DateTimeFormat.forPattern(pattern);

String tsStr = "2012.03.07.17.15.07.91".replace(".", "");

// SimpleDateFormatwill parse 91 as 91ms, Joda 2.0 will parse it as 910ms
Date javaDate = javaDateFormatter.parse(tsStr);
Date jodaDate = jodaDateFormatter.parseDateTime(tsStr).toDate();
assertThat(jodaDate.getTime() - 910 + 91, equalTo(javaDate.getTime()));

Regards
Wojtek


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Incompatibility between JodaTime and JavaTime

jodastephen
Yes there is a difference. Joda-Time is correct and SimpleDateFormat is wrong.

0.91 is 91/100th of a second, which is 910ms

Stephen


On 9 March 2012 10:29, Wojtek K <[hidden email]> wrote:

> Hi All,
>
> Is there a difference between DateTimeFormatter and SimpleDateFormat
> in respect of parsing milliseconds?  This is my test code:
>
> String pattern = "yyyyMMddHHmmssSS";
>
> SimpleDateFormat javaDateFormatter = new SimpleDateFormat(pattern);
> DateTimeFormatter jodaDateFormatter = DateTimeFormat.forPattern(pattern);
>
> String tsStr = "2012.03.07.17.15.07.91".replace(".", "");
>
> // SimpleDateFormatwill parse 91 as 91ms, Joda 2.0 will parse it as 910ms
> Date javaDate = javaDateFormatter.parse(tsStr);
> Date jodaDate = jodaDateFormatter.parseDateTime(tsStr).toDate();
> assertThat(jodaDate.getTime() - 910 + 91, equalTo(javaDate.getTime()));
>
> Regards
> Wojtek
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Incompatibility between JodaTime and JavaTime

Wojtek K
Thanks for the answer. We have multiple external systems that keep  
sending us timestamps in 'SS' format - two digits should be  
interpreted as 0SS e.g.(13 should be treated as 13ms).

Regardless the fact that Joda is right, I am wonder if there is a  
right approach for conversion instead of doing string manipulation of  
the input message?

Regards
w.

Quoting Stephen Colebourne <[hidden email]>:

> Yes there is a difference. Joda-Time is correct and SimpleDateFormat  
> is wrong.
>
> 0.91 is 91/100th of a second, which is 910ms
>
> Stephen
>
>
> On 9 March 2012 10:29, Wojtek K <[hidden email]> wrote:
>> Hi All,
>>
>> Is there a difference between DateTimeFormatter and SimpleDateFormat
>> in respect of parsing milliseconds?  This is my test code:
>>
>> String pattern = "yyyyMMddHHmmssSS";
>>
>> SimpleDateFormat javaDateFormatter = new SimpleDateFormat(pattern);
>> DateTimeFormatter jodaDateFormatter = DateTimeFormat.forPattern(pattern);
>>
>> String tsStr = "2012.03.07.17.15.07.91".replace(".", "");
>>
>> // SimpleDateFormatwill parse 91 as 91ms, Joda 2.0 will parse it as 910ms
>> Date javaDate = javaDateFormatter.parse(tsStr);
>> Date jodaDate = jodaDateFormatter.parseDateTime(tsStr).toDate();
>> assertThat(jodaDate.getTime() - 910 + 91, equalTo(javaDate.getTime()));
>>
>> Regards
>> Wojtek
>>
>>
>> ------------------------------------------------------------------------------
>> Virtualization & Cloud Management Using Capacity Planning
>> Cloud computing makes use of virtualization - but cloud computing
>> also focuses on allowing computing to be delivered as a service.
>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Incompatibility between JodaTime and JavaTime

jodastephen
You can use DateTimeFormatterBuilder to manually create a format.

DTFormatter f = new
DTFBuilder().appendPattern("yyyyMMddHHmmss").appendMillisOfSecond(2).toFormatter();

Stephen


On 9 March 2012 12:25, Wojtek K <[hidden email]> wrote:

> Thanks for the answer. We have multiple external systems that keep
> sending us timestamps in 'SS' format - two digits should be
> interpreted as 0SS e.g.(13 should be treated as 13ms).
>
> Regardless the fact that Joda is right, I am wonder if there is a
> right approach for conversion instead of doing string manipulation of
> the input message?
>
> Regards
> w.
>
> Quoting Stephen Colebourne <[hidden email]>:
>
>> Yes there is a difference. Joda-Time is correct and SimpleDateFormat
>> is wrong.
>>
>> 0.91 is 91/100th of a second, which is 910ms
>>
>> Stephen
>>
>>
>> On 9 March 2012 10:29, Wojtek K <[hidden email]> wrote:
>>> Hi All,
>>>
>>> Is there a difference between DateTimeFormatter and SimpleDateFormat
>>> in respect of parsing milliseconds?  This is my test code:
>>>
>>> String pattern = "yyyyMMddHHmmssSS";
>>>
>>> SimpleDateFormat javaDateFormatter = new SimpleDateFormat(pattern);
>>> DateTimeFormatter jodaDateFormatter = DateTimeFormat.forPattern(pattern);
>>>
>>> String tsStr = "2012.03.07.17.15.07.91".replace(".", "");
>>>
>>> // SimpleDateFormatwill parse 91 as 91ms, Joda 2.0 will parse it as 910ms
>>> Date javaDate = javaDateFormatter.parse(tsStr);
>>> Date jodaDate = jodaDateFormatter.parseDateTime(tsStr).toDate();
>>> assertThat(jodaDate.getTime() - 910 + 91, equalTo(javaDate.getTime()));
>>>
>>> Regards
>>> Wojtek
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Virtualization & Cloud Management Using Capacity Planning
>>> Cloud computing makes use of virtualization - but cloud computing
>>> also focuses on allowing computing to be delivered as a service.
>>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>> ------------------------------------------------------------------------------
>> Virtualization & Cloud Management Using Capacity Planning
>> Cloud computing makes use of virtualization - but cloud computing
>> also focuses on allowing computing to be delivered as a service.
>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Incompatibility between JodaTime and JavaTime

Wojtek K
Brilliant! Thanks a lot!

Quoting Stephen Colebourne <[hidden email]>:

> You can use DateTimeFormatterBuilder to manually create a format.
>
> DTFormatter f = new
> DTFBuilder().appendPattern("yyyyMMddHHmmss").appendMillisOfSecond(2).toFormatter();
>
> Stephen
>
>
> On 9 March 2012 12:25, Wojtek K <[hidden email]> wrote:
>> Thanks for the answer. We have multiple external systems that keep
>> sending us timestamps in 'SS' format - two digits should be
>> interpreted as 0SS e.g.(13 should be treated as 13ms).
>>
>> Regardless the fact that Joda is right, I am wonder if there is a
>> right approach for conversion instead of doing string manipulation of
>> the input message?
>>
>> Regards
>> w.
>>
>> Quoting Stephen Colebourne <[hidden email]>:
>>
>>> Yes there is a difference. Joda-Time is correct and SimpleDateFormat
>>> is wrong.
>>>
>>> 0.91 is 91/100th of a second, which is 910ms
>>>
>>> Stephen
>>>
>>>
>>> On 9 March 2012 10:29, Wojtek K <[hidden email]> wrote:
>>>> Hi All,
>>>>
>>>> Is there a difference between DateTimeFormatter and SimpleDateFormat
>>>> in respect of parsing milliseconds?  This is my test code:
>>>>
>>>> String pattern = "yyyyMMddHHmmssSS";
>>>>
>>>> SimpleDateFormat javaDateFormatter = new SimpleDateFormat(pattern);
>>>> DateTimeFormatter jodaDateFormatter = DateTimeFormat.forPattern(pattern);
>>>>
>>>> String tsStr = "2012.03.07.17.15.07.91".replace(".", "");
>>>>
>>>> // SimpleDateFormatwill parse 91 as 91ms, Joda 2.0 will parse it as 910ms
>>>> Date javaDate = javaDateFormatter.parse(tsStr);
>>>> Date jodaDate = jodaDateFormatter.parseDateTime(tsStr).toDate();
>>>> assertThat(jodaDate.getTime() - 910 + 91, equalTo(javaDate.getTime()));
>>>>
>>>> Regards
>>>> Wojtek
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Virtualization & Cloud Management Using Capacity Planning
>>>> Cloud computing makes use of virtualization - but cloud computing
>>>> also focuses on allowing computing to be delivered as a service.
>>>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>>>> _______________________________________________
>>>> Joda-interest mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>> ------------------------------------------------------------------------------
>>> Virtualization & Cloud Management Using Capacity Planning
>>> Cloud computing makes use of virtualization - but cloud computing
>>> also focuses on allowing computing to be delivered as a service.
>>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Virtualization & Cloud Management Using Capacity Planning
>> Cloud computing makes use of virtualization - but cloud computing
>> also focuses on allowing computing to be delivered as a service.
>> http://www.accelacomm.com/jaw/sfnl/114/51521223/
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...