开发者

wrong month in date parsing [closed]

开发者 https://www.devze.com 2023-03-21 21:40 出处:网络
开发者_JAVA百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form
开发者_JAVA百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a string in the following format.

07/06/2011 5:06
mm/dd/yyyy hh:mm

am using following code

DateFormat dateFormater = new SimpleDateFormat("mm/dd/yyyy hh:mm");
date = (Date)dateFormater.parse(dateTimeStr);


but for input = 03/05/2011 9:45
i get op = Wed Jan 05 09:45:00 IST 2011 

Why so?I gave month as march but i am getting jan as month

Whats the issue with my code?


You need to change the format to MM/dd/yyyy hh:mm ref: http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html


Months use capital M - MM/dd/yyyy - check the docs


You're aware that month is an uppercase M, right?


Try this one: MM/dd/yyyy hh:mm mm stands for minute in hour. But you need MM which stands for Month in year.

0

精彩评论

暂无评论...
验证码 换一张
取 消