Allow Parse format string
The problem is your dateToIso method. No need for this. The DateTimeFormatter object task is a parsing of a string in a given format. You really gave it the right format. And then you went and turned the string into a different format!
Solution: (a) Kill your dateToIso method. (b) Delete the call to this method. Just pass the source string to parseDateTime .
Side problem: you ignored the time zone problem. Therefore, when parsing this line, Joda-Time will receive an event of the time that occurred in your default JVM time zone. Thus, running the same code with the same inputs, but on a different computer / JVM with different time zone settings, will lead to a different result . Probably not what you want. Lesson learned: Always specify the time zone, rather than relying on the default value.
Another problem: the error you indicated is another problem moving from Joda-Time to Google. Read on.
Reading a document
If you are trying to convert an org.joda.time.DateTime object to a com.google.api.client.util.DateTime object, just look at the JavaDoc . There you will see that the Google DateTime constructor takes java.util.Date. Joda-Time has a built-in toDate method to convert to a java.util.Date object to interact with other classes.
Food chain
Create a product chain, for example:
org.joda.time.DateTime → java.util.Date → com.google.api.client.util.DateTime
Invalid code ...
org.joda.time.DateTimeZone = org.joda.time.DateTimeZone.forID( "Africa/Johannesburg" ); org.joda.time.DateTime jodaDateTime = new DateTime( timeZone ); // Convert from Joda-Time to old bundled juDate java.util.Date juDate = jodaDateTime.toDate(); // Convert from juDate to Google Date. com.google.api.client.util.DateTime googleDateTime = new com.google.api.client.util.DateTime( juDate );
milliseconds
Alternatively, you can extract and pass milliseconds.
I usually recommend avoiding direct milliseconds where possible. Using milliseconds can be confusing, inaccurate, and error prone. The millisecond count is difficult to debug, because people cannot easily decrypt the value of the long date. While Joda-Time and java.util.Date use milliseconds, since-Unix-epoch as their internal time tracking mechanism ...
Switching to another direction
[The next section assumes that Google has superseded the API referenced by the question with the new API. Not sure if this assumption is true.]
Moving from the com.google.gdata.data.DateTime object to the Joda-TimeTime time date, I would use count- milliseconds from the era provided by the getValue method. Note that it returns a 64-bit long , not a 32-bit int .
Be sure to set the required Joda-Time DateTime time zone, and do not rely on the implicit JVM assignment of the current default time zone .
long millisecondsFromUnixEpoch = myGoogleDateTime.getValue(); org.joda.time.DateTimeZone zone = DateTimeZone.forID( "Africa/Johannesburg" ); org.joda.time.DateTime jodaDateTime = new DateTime( millisecondsFromUnixEpoch, zone );
The Google API provides several other options.
toStringRfc822
You can call the toStringRfc822 method to generate a string that will be processed by Joda-Time. Unfortunately, RFC 822 is inconvenient and ambiguous for parsing. Among other errors, he uses non-standard, non-specific 3-4-hour time zone codes, rather than the correct time zone names . Joda-Time refuses to try to parse these codes because of their ambiguity. I believe that Google only includes it here for backward compatibility with older APIs / libraries. Modern Internet protocols have switched to ISO 8601.
toUiString
Perhaps you could call the toUiString method to create a string that will be processed by Joda-Time. Unfortunately, their documentation does not explain what format is used by this method.
toString
You can call the toString method, which is documented as creating an xs:dateTime string. The doc cannot explain exactly, but I assume that they mean that the ISO 8601 is included in the XML Schema specification. You can try this method to find out what it generates. This can be useful if you want to keep the UTC offset embedded in the Google object. But remember that the time zone is greater than the offset from UTC, so you should still assign the desired / expected time zone to your Joda-Time DateTime object. So I'm not sure if this is better than just passing a long count-from-epoch to the Joda-Time DateTime constructor.
java.time
Now that Java 8 has been released, it is possible that Google could upgrade its APIs to use java.time .
Note that java.time extends the ISO 8601 format to add a formal time zone name, a very useful idea.