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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -