【发布时间】:2018-04-18 01:00:20
【问题描述】:
我从 API 中提取数据以获取日期和值数组。日期都是纪元时间,例如1523912075000。我正在尝试制作图表,我的问题是我不知道如何更改标准 `MM/DD/YYYY 中的整个数组。我尝试使用下面的代码,但日期根本没有改变。寻求帮助。
public void onResponse(String response){
Log.d(TAG, "Response: " + response);
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("price");
for (int i = 0; i < jsonArray.length(); i++) {
Long date = jsonArray.getJSONArray(i).optLong(0);
Long value = jsonArray.getJSONArray(i).optLong(1);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.format(new Date(date));
x.add(new Entry(date, value));
}
...}
【问题讨论】:
-
看看javadocs,看看
format返回什么——String
标签: java android json android-volley