为了账号安全,请及时绑定邮箱和手机立即绑定

来自 JSON API 的设备中显示的日期格式错误

来自 JSON API 的设备中显示的日期格式错误

吃鸡游戏 2022-05-21 20:29:41
我在活动布局中显示了我的 JSON 日期,但它给了我这种日期格式“1547458358000”。如何将日期格式更改为 YYYY-MM-dd k:mm:s?appAdded 的日期来自 JSON API。从测试结果来看。我收到的 toast 消息是 API TIME 显示为 1547458358000 而 outDatedAPI 显示为空。 try {    SimpleDateFormat DateformatAPKAPIInstalled = new SimpleDateFormat("YYYY-MM-dd k:mm:s");        APITime = DateformatAPKAPIInstalled.parse(appAdded);        SimpleDateFormat outputFormat = new SimpleDateFormat("YYYY-MM-dd k:mm:s");         outputDateAPI = outputFormat.format(APITime);        Toast.makeText(FirstPageActivity.this, "DATE KO" dateAPKUpdated + appAdded + APITime, Toast.LENGTH_LONG).show();    } catch (ParseException e) {        e.printStackTrace();    }
查看完整描述

1 回答

?
潇湘沐

TA贡献1816条经验 获得超6个赞

您可以传递长时间戳,并可以使用以下代码将其转换为日期


private String getDate(long time) {

    Calendar cal = Calendar.getInstance(Locale.ENGLISH);

    cal.setTimeInMillis(time);

    String date = DateFormat.format("yyyy-MM-dd", cal).toString();

    return date;

}


查看完整回答
反对 回复 2022-05-21
  • 1 回答
  • 0 关注
  • 88 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号