jodatime

Joda Time bug or my mistake? (Java Joda Time dates as strings parsing)

Hi, so I was having a problem parsing a date, using the JodaTime chronology IslamicChronology so wrote a small example to demonstrate my problem. Here's the code: import org.joda.time.Chronology; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormat; import org.joda.time.chrono.IslamicChronology; im...

How to parse four digit year only (with Joda Time)?

Is there a way to force Joda time to parse dates only when they contain four digit years? For example: 2009-11-11 - should parse 09-11-11 - should not parse Tried the following code: DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendYear(4, 4).appendLiteral('-').appendMont...

Joda-Time: How to get the next friday?

How can I get the next friday with the Joda-Time API. The LocalDate of today is today. It looks to me you have to decide whever you are before or after the friday of the current week. See this method: private LocalDate calcNextFriday(LocalDate d) { LocalDate friday = d.dayOfWeek().setCopy(5); if (d.isBefore(friday)) { return d.dayO...

"Resource not found" when building Android app under IntelliJ 9.0 Maia Public Beta

I'm trying to port an app from Eclipse to IntelliJ. The app builds fine but it fails to run properly. Here's a partial stack trace I receive: ERROR/AndroidRuntime(957): java.io.IOException: Resource not found: "org/joda/time/tz/data/ZoneInfoMap" ClassLoader: dalvik.system.PathClassLoader@43761190 at org.joda.time....

Jodatime : what is there to keep up to date?

I read (dont't know where anymore, but see here) when using Jodatime you have to keep files up to date. What kind of files? Why is that? ...

Joda Time gives wrong time zone

I'm using the Joda time (1.6) libraries and it keeps returning DateTime objects with the wrong time zone, British Summer Time instead of GMT. My Windows workstation (running JDK 1.6.0_16) thinks it's in GMT and if I get the default time zone from the JDK date/time classes it is correct (GMT). I get the same behaviour on our Linux server...

How to print out time zone abbreviations when using offset hours in Joda Time?

I'm using Joda Time, and I'm being passed DateTimeZones that are created using DateTimeZone.forOffsetHours(). I'd like to print these timezones using standard timezone acronyms such as "PST", "EST", etc. However, whenever I print DateTimes that use these timezones, I get an "hh:mm" representation of the timezone instead of the name acr...

Joda Time to be included in Java 7?

I've read rumors that Joda Time is slated to be included in Java 7, but am having trouble locating a definitive source for this information. Will Joda Time be included in a future JDK? Please cite your source. ...

Best way to calculate next date from start plus frequency using joda time

Hi all I want to work out the next payment date in my code. I have a start date and i have a payment frequency which can be DAY, WEEK, MONTH or YEAR. So if the start date was 10 FEB 2009 and had a payment frequency of MONTH and the current date is 13 NOV 2009 then the next payment date would be 10 DEC 2009 I have already written some ...

javadoc for ISODateTimeFormat.dateTime()

The javadoc for org.joda.time.format.ISODateTimeFormat.dateTime() is: Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ). The time zone offset is 'Z' for zero, and of the form '±HH:mm' for non-zero. It is not clear to me where the word 'zero' is pointing at/to. Zero where or wha...

Joda Time: First day of week??

How do you get the first day of week given a Locale using Joda Time? Point: Most countries use the international standard Monday as first day of week (!). A bunch others use Sunday (notably USA). Others apparently Saturday. Some apparently Wednesday?! Wikipedia "Seven-day week"#Week_number ...

How to query a date in HQL (Hibernate) with Joda Time?

I am sure that someone familiar with HQL (I am myself a newbie) can easily answer this question. In my Grails application, I have the following domain class. class Book { org.joda.time.DateTime releaseDate //I use the PersistentDateTime for persisting via Hibernate (that use a DATETIME type for MySQL DB) } In my HQL query, I want t...

Create jodatime LocalDate from java.sql.Time

I'm new to joda-time and I didn't find anywhere examples to do some simple things. I want to make an object where to save a time value read from a table in a database (a java.sql.Time - e.g. "18:30:00") I don't care about time zone, so I think that I need LocalDate. But the problem is that I couldn't create a LocalDate object based on t...

Can I parse relative times with JodaTime?

I'd love to be able to parse relative strings like now and yesterday and get JodaTime DateTimes. Is it possible? DateTimeFormat.forPattern and doesn't seem to support English relative times and I don't know of any other parsing options in JodaTime. I should add that I'm using scala-time but can easily drop down to the actual JodaTime cl...

The API Joda-Time(java) doesnt respect the ISO 8601: bug or feature ?

Hi, According to their website, the class DUration implements the ISO 8601 http://en.wikipedia.org/wiki/ISO%5F8601#Durations But let see an example. It is a duration of 14min & 51sec. In ISO 8601 those code are equivalent : PT14M51S PT891S System.out.println("bug "+new Duration("PT14M51S")); System.out.println("NO bug "+new...

Using Groovy(or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.date?

Using Groovy (or Java) how can I convert a org.joda.time.LocalDateTime to a java.util.Date? import org.joda.time.* Calendar cal = Calendar.instance cal.set(Calendar.DATE, 1) cal.set(Calendar.HOUR, 0) cal.set(Calendar.MINUTE, 0) cal.set(Calendar.SECOND, 0) cal.set(Calendar.MILLISECOND, 0) Date startOfTheMonth = cal....

Jodatime - Custom Chronology

Hello, I would like to calculate a duration whereas 1 day will consist of 8 hours. Is creating a new Chronology is the right approach ? I did try to create a custom Chronology and override the assemble method with something like: int millisPerDay = 1000 * 60 * 60 * 8; fields.days = new PreciseDurationField(DurationFieldType.days(), m...

Correctly defining a duration using JodaTime

I've created a method that takes two dates (in milliseconds) and returns a sentence that indicates the duration between these two dates. For the moment, I have this code: public static String formatDuration(long start, long end) { Interval interval = new Interval(start, end); return getPeriodFormatter().print(interval.toPeriod(...

JodaTime Calculate total hours worked in a week

Currently I have a function which can take the start time and end time of one day, and calculate the difference between the two, giving me the hours worked in a day. What I would like to do is be able to get the hours worked for 7 days, and return a grand total, while remaining with the display format (HH:mm). My function for a single d...

What's the best way of using joda time to manipulate monthly data?

I'm trying to work with a timeseries of monthly data. That is, there is a value for each month, and no specific date (or time) associated with it. I could have arbitrarily fixed the day, time at some constant (eg midnight on first of the month) then used a java.util.date or joda DateTime but decided to try and do this within the joda t...