尝试获取 Android CallLog.Calls 上的日期时出错
嘿,我正在尝试从 Android 中的 CallLog.Calls 获取日期。我这样做:
import org.apache.http.impl.cookie.DateUtils;
import android.database.Cursor;
Cursor cursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC ");
int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
String callDate = cursor.getString(dateId);
String dateString = DateUtils.formatDate(callDate);
但是 formatDate
方法不允许 String
作为参数,它需要一个 Date
参数。我尝试过选角,但我认为这是不对的。那么,有人知道如何做到这一点吗?
谢谢。
Hey I'm trying to get the date from the CallLog.Calls in Android. I'm doing like this:
import org.apache.http.impl.cookie.DateUtils;
import android.database.Cursor;
Cursor cursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC ");
int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
String callDate = cursor.getString(dateId);
String dateString = DateUtils.formatDate(callDate);
But the formatDate
method doesn't allow String
as parameter, it needs a Date
parameter. I've tried to make a cast, but I don't think it's right. So, someone have an idea of how to do that?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以解析字符串并获取日期 - http://developer.android.com/reference/java/text/DateFormat.html#parse(java.lang.String)
Perhaps you can parse the string and get a date - http://developer.android.com/reference/java/text/DateFormat.html#parse(java.lang.String)