Tam*_*arG 7 android calendar milliseconds year2038
我正在构建一个Android应用程序,该应用程序使用户可以将事件插入到Google日历和外部日历(如Exchange帐户).
问题在于,如果用户想要在2038年之后添加事件,则会在过去创建事件(例如 - 2038年1月变为1901年12月,2038年7月4日变为1902年5月28日).我做了一些研究,发现问题是" 2038年问题 ".
2038年问题是计算和数据存储情况的问题,其中时间值存储或计算为带符号的32位整数,并且此数字被解释为1970年1月1日00:00:00 UTC以来的秒数这种实现无法在2038年1月19日03:14:07 UTC之后编码.
可以用Unix签名的32位整数时间格式表示的最新时间是2038年1月19日星期二03:14:07 UTC(1970年1月1日之后的2,147,483,647秒).超出该时间的时间将"环绕"并在内部存储为负数,这些系统将解释为1901年12月13日而不是2038年1月19日.这是由整数溢出引起的.
似乎我的Java代码工作正常,我得到的毫秒是好的,但是当我将值发送到Google API insert函数时 - 我认为它不知道如何处理它然后它在错误的日期插入事件( 1901年及以上).有办法处理吗?
这是我的代码:
private void InsertEvent(MyEvent myEvent) {
Uri EVENTS_URI = Uri.parse(getCalendarUriBase() + "events");
ContentValues eventValues = new ContentValues();
eventValues.put("eventTimezone", TimeZone.getDefault().getID());
eventValues.put("calendar_id", myEvent.calId);
eventValues.put("title",myEvent.title);
eventValues.put("allDay", 1);
long dateStart = myEvent.startDate.getTime(); // returns milliseconds - 2160248400000 for date 06/16/2038
eventValues.put("dtstart", dateStart );
long dateEnd = myEvent.endDate.getTime();
eventValues.put("dtend", dateEnd );
// At this point, in debug mode, I can see that the millisecond of dtstart and dtend are OK.
Uri u1 = contentResolver.insert(EVENTS_URI, eventValues ); // API's function
}
Run Code Online (Sandbox Code Playgroud)
这是关于插入活动的Google文档:http: //developer.android.com/guide/topics/providers/calendar-provider.html#add-event
如果没有您的所有代码,我无法完全提供帮助,但我之前遇到过类似的问题。我会检查您是否没有沿着数据管道将任何内容转换为 int 。
1.) 检查 MyEvent getTime() 不返回 int
2.) 检查 MyEvent SetTime 是否未将其设置为 int
3.) 检查是否存在其他 int 类型转换。
如果您要转换为 int、隐式或显式,那么 java 会将您的数字转换为数字的负数表示形式。
| 归档时间: |
|
| 查看次数: |
638 次 |
| 最近记录: |