我有一个字符串是时间戳,想把它转换成日历对象,以便在我的Android应用程序中显示。
到目前为止,我的代码显示的所有内容都是在1970年代。
String timestamp = parameter.fieldParameterStringValue;
timestampLong = Long.parseLong(timestamp);
Date d = new Date(timestampLong);
Calendar c = Calendar.getInstance();
c.setTime(d);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int date = c.get(Calendar.DATE);
dateTextView.setText(year + "-" + month + 1 + "-" + date);
更新: 只是提醒一下,服务器的时间戳是:1369148661, 这可能是错误的吗?
c.setTimeInMillis(timestampLong);
代码,看看是否会得到相同的结果? - Alexis C.