java date format with 6 digit micro/milli second -


from postgres database getting 6 digit microsecond (its ) e.g. 2014-11-10 04:05:06.999999

now when apply date format of "yyyy-mm-dd hh:mm:ss.sss" converts 999999 corresponding seconds/minutes resulting in incorrect date. see code snippet below

string dt = "2014-11-10 04:05:06.999999";                    string timeseriesformat = "yyyy-mm-dd hh:mm:ss.sss";                     simpledateformat dateformat = new simpledateformat(timeseriesformat);         date date = dateformat.parse(dt);         system.out.println(dateformat.format(date)); 

results in 2014-11-10 04:21:45.999

i want rather truncate last 3 digits , keep date of 2014-11-10 04:05:06.999. how truncate it? not want use framework joda etc.

duplicate 1 custom date format cannot parsed.

conculsion simpeldateformat not support microsecond, , you'll need own parser

try this

system.out.println( new simpledateformat("yyyy-mm-dd hh:mm:ss.").format(microseconds/1000) +string.format("%06d", microseconds%1000000)); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -