本文介绍了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日期
发布评论