JSON日期格式化JAVA日期

编程入门 行业动态 更新时间:2024-10-20 03:41:40
本文介绍了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日期

本文发布于:2023-10-25 08:31:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   JSON   JAVA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!