java - Why does my date parsing return a weird date? -


here code using:

string string = "08/07/2013".replace('/', '-'); date date = new simpledateformat("yyyy-mm-dd").parse(string); 

why date return: "wen jan 3 00:00:00 est 14"? not @ date format told use.

edit: need format because database using requires format.

the format use parse date string, not match it. using yyyy 08.

use following format:

new simpledateformat("dd-mm-yyyy") 

and why @ replacing / -? can build pattern original string only:

string string = "08/07/2013" date date = new simpledateformat("dd/mm/yyyy").parse(string); 

and if want date string in yyyy-mm-dd format, can format date using dateformat#format(date) method:

string formatteddate = new simpledateformat("yyyy-mm-dd").format(date); 

see also:


Comments

Popular posts from this blog

android - Invite new users for my app using app notifications facebook -

html - CSS: Combine Texture and Color -

Need help in packaging app using TideSDK on Windows -