java - How to format my date with SimpleDateFormat? -
i'm trying set date format, when run code string oldstring = "2013-01-1"; system.out.println("oldstring = "+oldstring); date date = new simpledateformat("yyyy-mm-dd").parse(oldstring); system.out.println("datefield = "+date); i take result: oldstring = 2013-01-1 datefield = tue jan 01 00:01:00 msk 2013 why datefield isn't equal 2013-01-1? the type of datefield date, tostring method return same format, not overriding it. so need do, basically: string oldstring = "2013-01-1"; system.out.println("oldstring = "+oldstring); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); date date = sdf.parse(oldstring); system.out.println("datefield = "+date); string outdatestr = sdf.format(date); system.out.println("newstring = "+outdatestr);