【发布时间】:2014-05-22 11:36:42
【问题描述】:
我正在使用 achartengine 开发 android 应用程序,我正在制作 TimeSeries 折线图。我已将所有变量存储在 Arraylist 中。由于我需要正确的日期对象来插入我正在使用的图表的时间轴,
int count = list.size();
Date[] dt = new Date[count];
for(int i=0;i<count;i++){
long a = Long.parseLong(list.get(i).get("time"));
dt[i] = new Date(a);
}
这里long a 有时间戳。有了上面的代码。我可以将dt 设为09-Apr-2014,但我需要将日期显示为09-Apr 12:55。我该怎么做呢,
我尝试使用以下
SimpleDateFormat sdfDate = new SimpleDateFormat("MM-dd HH:mm");
Date now = new Date();
String strDate = sdfDate.format(now);
但是由于 strDate 是一个字符串,我不能将它用作 dt[i] = strDate,这会引发错误,因为一个是 Date,另一个是 String。
我该如何解决这个问题?
谢谢
【问题讨论】:
-
strDate 是一个字符串 请显示一个日期示例
-
我不明白你的问题。但如果我理解正确,那么
Date[] dt = new Date[count];和String strDate显然不是同一数据类型。由于strDate会将时间戳转换为正确的日期格式,但它将存储在字符串中。
标签: java android date timestamp achartengine