James James - 5 months ago 48
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) {
// 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

2016/09/07 14:19:03

Process finished with exit code 0

Fixed. Thanks.


Try this code:

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

D = Day in year

d = Day in month