java - SimpleDateFormat cannot parse milliseconds with more than 4 digits -
i want parse timestamp, - "2016-03-16 01:14:21.6739"
. when use simpledateformat
parse it, find outputs incorrect parsed value. covert 6739 milliseconds 6 seconds 739 millseconds left. converted date format - wed mar 16 01:14:27 pdt 2016
. why seconds part has changed 21 seconds 27 seconds(an addition of 6 seconds?). following code snippet:
final simpledateformat sf = new simpledateformat("yyyy-mm-dd hh:mm:ss.ssss"); string parsedate="2016-03-16 01:14:21.6739"; try { date outputdate = sf.parse(parsedate); string newdate = outputdate.tostring(); //==output date is: wed mar 16 01:14:27 pdt 2016 system.out.println(newdate); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); }
it seems not possible use simpledateformat express times finer grain millisecond. happening put 6739, java understands 6739 milliseconds i.e. 6 seconds , 739 milliseconds hence 6 seconds difference observed.
check these ones, explained quite well: string-date conversion nanoseconds java date parsing microsecond or nanosecond accuracy
Comments
Post a Comment