简体   繁体   English

不兼容的类型:com.google.api.client.util.DateTime 无法转换为 org.joda.time.DateTime

[英]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 .我想将 Google DateTime转换为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 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。爪哇

How I can implement this?我该如何实施?

Returns the date/time value expressed as the number of milliseconds since the Unix epoch.返回日期/时间值,表示为自 Unix 纪元以来的毫秒数。 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.如果指定了时区,则此值将标准化为 UTC,因此要格式化此日期/时间值,必须应用时区偏移。


public DateTime(long instant)公共日期时间(长瞬间)

Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the default time zone.在默认时区中使用 ISOChronology 构造一个设置为 1970-01-01T00:00:00Z 毫秒的实例。


// 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这会从 google DateTimes 的 long 值创建一个新的 joda DateTime

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找到:'java.util.Date',需要:'com.google.api.client.util.DateTime' GAE - Found: 'java.util.Date', required: 'com.google.api.client.util.DateTime' GAE 如何将org.joda.time.DateTime转换为com.mindfusion.common.DateTime - How to convert org.joda.time.DateTime to com.mindfusion.common.DateTime 数据截断:错误的日期时间值:org.joda.time.DateTime - Data truncation: Incorrect datetime value: org.joda.time.DateTime 从org.joda.time.DateTime转换为java.util.Calendar的方法 - Approach to convert from org.joda.time.DateTime to java.util.Calendar java org.joda.time.DateTime非法模式 - java org.joda.time.DateTime illegal pattern Java EE:使用IntelliJ和Maven的NoClassDefFoundError org.joda.time.DateTime - Java EE: NoClassDefFoundError org.joda.time.DateTime with IntelliJ and Maven Spring bean无法解析org.joda.time.DateTime的构造函数 - Spring bean unable to resolve constructor for org.joda.time.DateTime 将 org.joda.time.DateTime 作为字符串而不是 object 写入数据库? - Write org.joda.time.DateTime to DB as string instead of object? 无法将类型类java.sql.Timestamp转换为类org.joda.time.DateTime - Cannot convert of type class java.sql.Timestamp to class org.joda.time.DateTime 内存消耗java.util.Date与java.time.LocalDate与org.joda.time.DateTime - Memory consumption java.util.Date vs java.time.LocalDate vs org.joda.time.DateTime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM