eclipse - Encountering issue in SimpleDateFormat parse method in Java -


i trying use simpledateformat.parse method parse date string date object, omitting "t" in final date returned. passing date string 2015-04-15t12:55:07.365 , getting 2015-04-15 12:55:07.365 in output. however, desired output 2015-04-15t12:55:07.365.

why "t" in final output omitted line parseddate = sdf.parse(transdate);

public static void main(string[] args)  {      try      {         final string pattern = "yyyy-mm-dd't'hh:mm:ss.sss";  // example 2015-04-15t12:55:07.365         final simpledateformat sdf = new simpledateformat(pattern);          string transdate = "2015-04-15t12:55:07.365";         date parseddate = sdf.parse(transdate);          system.out.println("transdate:"+transdate+", parseddate: "+parseddate);     }  

you never desired output 2015-04-15t12:55:07.365

why?

because printing date object parseddate.date class has it's own tostring() method implementation.when printing date object, means prints tostring() method implementation format.

see java doc details


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -