jodatime

How to calculate elapsed time from now with Joda Time?

I need to calculate the time elapsed from one specific date till now and display it with the same format as StackOverflow questions, i.e.: 15s ago 2min ago 2hours ago 2days ago 25th Dec 08 Do you know how to achieve it with the Java Joda Time library? Is there a helper method out there that already implements it, or should I write the...

Is it possible to get the previous day of the week using Joda-Time?

I am new to Joda-Time and was looking at getting the previous working/week day. My initial try was done on a Monday and I wanted to get the date for T -1 which will be Friday: DateTimeZone zone = DateTimeZone.forID("Europe/London"); Chronology coptic = GJChronology.getInstance(zone); DateTime dt = new DateTime(coptic); DateTime minus...

Persisting Joda DateTime instead of Java Date in hibernate

My entities currently contain java Date properties. I'm starting to use Joda Time for date manipulation and calculations quite frequently. This means that I'm constantly having to convert my Dates into Joda DateTime objects and back again. So I was wondering, is there any reason I shouldn't just change my entities to store Joda DateTi...

How do I figure out what namespace I need to import from a java library?

I'm writing some clojure code, and I'm relying on Joda time for time handling. The problem is that I don't know what to import and the documentation isn't terribly clear about it. Now I know that somebody here can probably give me the correct answer in less than 5 seconds, but I'd rather know how to figure this one out on my own (aside...

Joda time week calculation reasoning

Hello Friends, The code below demonstrates the problematic joda-time implementation of week calculation. This behavior is not a bug but a design decision Joda-Time uses the ISO standard Monday to Sunday week. (perhaps it should be a bug?) Given a date I need to calculate the week number, this calculation must be i18n in nature. Meaning...

My PeriodFormatter is not behaving as I expect - what have I done wrong?

I'm having trouble using Joda Time's PeriodFormatter. I want one to report days, hours, minutes and seconds but my attempt seems to be wrapping around weeks. What should I be doing differently? import org.joda.time.DateTime; import org.joda.time.Period; import org.joda.time.format.PeriodFormatter; import org.joda.time.format.PeriodFor...

set DateTime to start of month

Hello, My API allows library client to pass Date: method(java.util.Date date) Working with joda-time, from this date I would like to extract the month and iterate over all days this month contains. Now, the passed date is usually new Date() - meaning current instant. My problem actually is setting the new DateMidnight(jdkDate) insta...

Joda Time formats time at 24:xx:xx UTC should be 0:xx:xx UTC

I'm converting from a local time zone to UTC so when we convert 2010-01-03T11:15:58.840+11:00 => Sun, 03 Jan 2010 24:15:58 UTC This is technically correct but I'm having problems with the 24 hour formatting as it does. I have some BlackBerry J2ME code which is having problems parsing this date-time String using HttpDateParser. new Lo...

Odd results in Joda DateTime for 01.04.1893

My time zone is CET (Berlin). And while testing Joda's DateTime i noticed some strange things: new DateTime(1893, 4, 1, 0, 0, 0, 0); => java.lang.IllegalArgumentException: Illegal instant due to time zone offset transition: new DateTime(1893, 3, 31, 0, 0, 0, 0).toDate(); => Fri Mar 31 00:06:32 CET 1893 A 6 minute 32 seconds shift ...

Passing Joda Time objects between the App layers

I'm considering using Joda Time. I'm wondering if I should pay attention of what type of object my Interfaces are returning. Returning Joda Objects from my interface signature on the service layer means that every module that use it will have be dependent on jodaTime instead of the common Date API. Are you passing Joda objects around you...

Finding begin and end of year/month/day/hour

I'm using the following snipped to find the begin and end of several time periods in Joda. The little devil on my left shoulder says thats the way to go... but I dont believe him. Could anybody with some joda experience take a brief look and tell me that the little guy is right? (It will be only used for UTC datetime objects) Thank ...

Jodatime groovy/grails daterange search with TimeZone conversion

I am currently storing Joda DateTime (Datetime+TimeZone) values into a database. What I want to do grab 24 hours of records based on the timezone of the user, rather than UTC time. I.E. I want to grab the records between 00:00GMT-24:00GMT for people whose timezone is GMT, and 00:00PST-24:00PST for people whose timezone is PST. Now I do...

Partially constructed object / Multi threading

Heya! I'm using joda due to it's good reputation regarding multi threading. It goes great distances to make multi threaded date handling efficient, for example by making all Date/Time/DateTime objects immutable. But here's a situation where I'm not sure if Joda is really doing the right thing. It probably does, but I'm very interested ...

Joda-Time: DateTime, DateMidnight and LocalDate usage

Joda-Time library includes different datetime classes DateTime - Immutable replacement for JDK Calendar DateMidnight - Immutable class representing a date where the time is forced to midnight LocalDateTime - Immutable class representing a local date and time (no time zone) I'm wondering how are you using these classes in ...

Joda: what's the difference between Period, Interval and Duration?

Why do we need three classes? Which one performs better? Why is dividing a Period or Duration or Interval instance not implemented? E.g. p = p.divideBy(2); ...

Joda time : How to convert String to LocalDate?

Hello, How to specify the format string to convert the date alone from string. In my case, only the date part is relevant Constructing it as DateTime fails: String dateString = "2009-04-17"; DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTime dateTime = formatter.parseDateTime(dateString); with error jav...

passing timezone from client (GWT) to server (Joda Time)

I'm using GWT on the client (browser) and Joda Time on the server. I'd like to perform some DB lookups bounded by the day (i.e. 00:00:00 until 23:59:59) that a request comes in, with the time boundaries based on the user's (i.e. browser) timezone. So I have the GWT code do a new java.util.Date() to get the time of the request, and send...

Library to work with date expressions in C#?

What library can I use to calculate dates based on date expressions? A date expression would be something like: "+3D" (plus three days) "-1W" (minus one week) "-2Y+2D+1M" (minus 2 years, plus one day, plus one month) Example: DateTime EstimatedArrivalDate = CalcDate("+3D", DateTime.Now); Where estimated arrival date would equal t...

Calculating end date while skipping holidays + Joda time

I would like to calculate end date (and time) of an event. I know starting date and duration (in minutes). But: I have to skip holidays - non-recurrent situation I have to skip weekends - recurrent situation I have to not count working time (e.g: from 8:00am till 5:00pm) - recurrent situation, but with finer granularity Is there a s...

Rounding up milliseconds when printing with Joda Time

I'm implementing a count-down using Joda Time. I only need a display accuracy of seconds. However when printing the time, the seconds are displayed as full seconds, so when the count down reaches, for example, 900ms, then "0" seconds is printed, but as a count-down it would make more sense to display "1" second, until the time actually ...