解析日期不正确 [英] Incorrect Parsed Date

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

问题描述

我的代码:

DateFormat format = new SimpleDateFormat("dd/MM/YYYY");

Date Today = format.parse(today);
Date Date = format.parse(date);

difference = (Date.getTime() - Today.getTime()) / 86400000;
Math.abs(difference);
System.out.println(String.valueOf("date" + date));
System.out.println(String.valueOf("date" + Date));
System.out.println(String.valueOf("date" + today));
System.out.println(String.valueOf("date" + Today));

输出:
日期2016/11/29
dateSun 12月27日00:00:00 GMT + 08:00 2015
日期20/11/2016
dateSun十二月27 00:00:00 GMT + 08:00 2015

The output:
date29/11/2016
dateSun Dec 27 00:00:00 GMT+08:00 2015
date20/11/2016
dateSun Dec 27 00:00:00 GMT+08:00 2015

我在解析日期时遇到问题,原始日期是 2016/11/29 ,但是在解析时,日期变成了 Sun Dec 27 00:00:00 GMT + 08: 00 2015 .

与日期有关时,这个问题出现在我的整个程序中.

I have problems while parsing the date, the original date is 29/11/2016, however when parsed, the date becomes Sun Dec 27 00:00:00 GMT+08:00 2015.

This problem appears in my whole program whenevr it's related to date.

推荐答案

格式dd/MM/YYYY应该为dd/MM/yyyy.请参见SimpleDateFormat的javadoc:y =年,Y =周年. – 安德烈亚斯12分钟前

Format dd/MM/YYYY should be dd/MM/yyyy. See javadoc of SimpleDateFormat: y = Year, Y = Week year. – Andreas 12 mins ago

谢谢解决.

这篇关于解析日期不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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