Not able to convert string dd/MM/yyyy to Date dd/MM/yyyy in java -


i have input string of format dd/mm/yyyy, need convert date dd/mm/yyyy.

my approach is:

simpledateformat formatter = new simpledateformat("dd/mm/yyyy"); string date = formatter.format(formatter.parse("22/09/2016")); date converteddate = formatter.parse(date); 

i expecting 22/09/2016 date object, format returned not expected. o/p=>mon sep 12 00:00:00 ist 2016

any idea going wrong? in advance!

you seem assuming java.util.date "knows" format. doesn't. that's not part of state - it's just number of milliseconds since unix epoch. (there's no time zone either - ist you're seeing there local time zone; that's part of date.tostring() does.)

basically, date instant in time - when want particular formatted value, that's when use simpledateformat.

(or better, use java.time.*...)

think of number - number sixteen same number whether represent in binary 10000, decimal 16, or hex 0x10. int value doesn't have concept of "i'm binary integer" or "i'm hex integer" - it's when convert string need care formatting. exact same thing true date/time types.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -