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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -