James James - 2 months ago 15
Java Question

SimpleDateFormat of Date says this is the 251st day of September?

import java.text.SimpleDateFormat;
import java.util.Date;

public class SysDate {
public static void main(String[] args) {
System.out.println(
// new SimpleDateFormat("yyyy/MM/DD HH:mm:ss")
// right way
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
.format(new Date()));
}
}


2016/09/251 14:08:27

Process finished with exit code 0

Better
2016/09/07 14:19:03

Process finished with exit code 0

Fixed. Thanks.

Answer

Try this code:

new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

D = Day in year

d = Day in month

Comments