Invalid date value after parse

I am new to java. I have a Date that is stored in the variable, pubDate = "2013-09-23"

When I'm executing this

SimpleDateFormat pubSimpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
Date publishDate = pubSimpleDateFormat.parse(pubDate);

I'm getting wrong value : Wed Jan 23 00:09:00 GMT+05:30 2013

Please help me why it so. and help me to solve this.


M is for Month in year while m is for Minute in hour

You should use SimpleDateFormat pubSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

String pubDate = "2013-09-23";
SimpleDateFormat pubSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date publishDate = pubSimpleDateFormat.parse(pubDate);
System.out.println(publishDate);

Output :

Mon Sep 23 00:00:00 GMT 2013

Read the section Date and Time Patterns.

链接地址: http://www.djcxy.com/p/18604.html

上一篇: SimpleDateFormat在解析过程中返回错误的日期值

下一篇: 解析后的日期值无效