I want to get the current date in the following format yyyy_mm_dd
Am Using the below code
DateFormat date = new SimpleDateFormat("yyyy_mm_dd");
Date datetoday = new Date();
System.out.println(date.format(datetoday));
But its giving the result in this manner - 2013_56_25
However, it should give the result like 2013_03_25
Infact, the mm value varies every time I run it. My system's date is of the format - 3/25/2013. (Idk if it has some relation with this)
What is the possible problem with this ?
使用大写字母MM
,小写字母mm
持续几分钟。
DateFormat date = new SimpleDateFormat("yyyy_MM_dd");
月份是M,而不是m(分钟)
Use MM instead of mm ; lower case is for mintues; Uppercase for Months
You will have to use MM and not mm. Please refer the table from the image below
I got Different Result after parse the java.util.Date to java.sql.Date String date="2012-05-02";
SimpleDateFormat df=new SimpleDateFormat("yyyy-mm-dd");
i got as a result is:2012-01-01
means 1 Day is less than actually required.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.