JSON日期格式化JAVA日期 [英] JSON date to formatted JAVA date

查看:774
本文介绍了JSON日期格式化JAVA日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从1436536800得到dd.MM.yyyy和hh:mm,但只有时间是正确的,日期是完全错误的。我真的不明白这是如何工作的。

I am trying to get dd.MM.yyyy and hh:mm from 1436536800 but only the time is correct, the date is completely wrong. I don't really understand how this is supposed to work

int dt = time.getInt("start")*1000;
Date date = new Date(dt);
startDate = dateFormat.format(date);


推荐答案

如果time.getInt(start)是有效的unix时间戳,您必须在数字中添加000。例如:1436536800 * 1000 = 1436536800000.然后您可以使用时间戳来获取日期:

If time.getInt("start") is a valid unix timestamp, you must add "000" to the number. Example: 1436536800 * 1000 = 1436536800000. Then you can use the timestamp to get a Date:

final Date date = new Date(Long.parseLong("1436536800000"));
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy hh:mm");
System.out.println(sdf.format(date));

控制台退出:10.07.2015 09:00

Console exit: 10.07.2015 09:00

这篇关于JSON日期格式化JAVA日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆