简体   繁体   中英

Incompatible types: com.google.api.client.util.DateTime cannot be converted to org.joda.time.DateTime

I want to convert Google DateTime into org.joda.time.DateTime .

This is the code of Google's implementation.

http://grepcode.com/file/repo1.maven.org/maven2/com.google.http-client/google-http-client/1.15.0-rc/com/google/api/client/util/DateTime.java

How I can implement this?

Returns the date/time value expressed as the number of milliseconds since the Unix epoch. If the time zone is specified, this value is normalized to UTC, so to format this date/time value, the time zone shift has to be applied.


public DateTime(long instant)

Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the default time zone.


// getValue() return millis since epoch
long millis = googleDate.getValue();

// Which is accepted by Joda DateTime's constructor
DateTime jodaDate = new DateTime(millis);

Probably it is too late, but I have just solve a quite similar problem as follows

//Let's suppose date is our google DateTime
org.joda.time.DateTime jodaDate = date.getDateTime(date.getValue);

This creates a new joda DateTime from the google DateTimes' long value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM