I would take a look at the DateTimeFormatterBuilder and 
PeriodFormatterBuilder classes. If you still have trouble, please write 
back.

Stephen


Moritz Petersen wrote:
> Hello list,
> 
> I'm quite new to Joda Time but my first steps were quite successful  
> so far. Now I've stumbled about a problem which I don't really  
> understand.
> 
> First of all, I'd like to parse date in a "normal" format, not ISO,  
> but more casual.
> 
> A date is for example "21.08.2007"
> A time is for example "14:35"
> A date with a time (not midnight) is for example "21.08.2007 14:35"
> 
> For the date I would use a DateTime instance. Unfortunately, I cannot  
> use a String to instantiate the object as desired. Instead I've  
> written a utility class:
> 
> new DateTime(DateConverter.toMillis("21.08.2007"))
> 
> OK, this works, but is probably not the most elegant solution.
> 
> Now to the more nasty part: I would like to parse a time duration.  
> For example say a meeting starts at 14:00 and takes 4 hours. I would  
> like to compute the end date of the meeting. Here's my approach  
> (which doesn't work properly):
> 
>               DateTime start = new 
> DateTime(DateConverter.toMillis("21.08.2007  
> 14:00"));
>               Duration duration = new 
> Duration(DateConverter.toMillis("4:00"));
>               DateTime end = start.plus(duration);
>               assertEquals(new DateTime(DateConverter.toMillis("21.08.2007  
> 18:00")), end);
> 
> Which results in:
> 
> junit.framework.AssertionFailedError:  
> expected:<2007-08-21T18:00:00.000+02:00> but  
> was:<2007-08-21T17:00:00.000+02:00>
> 
> The DateConverter method works roughly (very simplified - but showing  
> the essential part) like this:
> 
> public long toMillis(String str) {
>      return DateTimeFormat.forPattern("HH:mm").parseMillis(str);
> }
> 
> 
> Now I have two questions:
> 
> a) is the way to convert a String to different Joda Time classes  
> correct this way or is there a better alternative?
> 
> b) Why does the Duration not work?
> 
> Regards,
> Moritz.
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
> 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to