Java – how to parse the “DD mm” date format to get the current year? “

I have to use java to parse the date in "17 - Jun" format The problem is that when I try to parse the "DD mm" format using simpledateformat, it will return "wed Jun 17 00:00:00 ist 1970" Yes, it is possible to get the current (2014) year instead of 1970

My result: 17 / June / 1970

Expected results: 17 / June / 2014

Solution

Look at this

Calendar c = Calendar.getInstance();
c.set(Calendar.DATE,17);
c.set(Calendar.MONTH,5);
c.set(Calendar.YEAR,c.get(Calendar.YEAR));
Date date=new Date(c.getTimeInMillis());
SimpleDateFormat simpleDateformatter = new SimpleDateFormat("dd/mmm/yyyy");
String convertedDate = simpleDateformatter .format(date);

To get a year, you can use

Calendar cal = Calendar.getInstance();
cal.get(Calendar.YEAR) will fetch you current year

I hope it helps

The above is the Java collected by programming house for you - how to parse the "DD mm" date format to get the current year? "All content, I hope this article can help you solve Java - how to parse the" DD mm "date format to get the current year? "Program development problems encountered.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>