datetime format - JAVA OffsetDateTime custom hundredth of second -


i looking custom format of date , can't obtain it.

i want obtain "1997-07-16t19:20:30.45+01:00" using following code :

offsetdatetime o = offsetdatetime.now(); string l = o.format(datetimeformatter.iso_date_time); 

the result is:

2017-03-28t16:23:57.489+02:00

very close, need have hh:mm:ss.xx, , not hh:mm:ss.xxx.

do know how customize offsetdatetime? can't find examples.

your answer almost correct. if take @ datetimeformatter javadoc, you'll see lowercase s corresponds seconds, , uppercase s, fraction of seconds:

symbol  meaning                     presentation      examples ------  -------                     ------------      ------- s       second-of-minute            number            55 s       fraction-of-second          fraction          978 

so, in pattern, s , s inverted. correct pattern is:

datetimeformatter formatter = datetimeformatter.ofpattern("yyyy-mm-dd't'hh:mm:ss.ssxxx"); offsetdatetime o = offsetdatetime.now(); system.out.println(o.format(formatter)); 

the output is:

2017-06-19t20:34:29.75-03:00


ps: note fraction of second 75 - greater 59, maximum value seconds (in answer, seems correct because fraction of second 48, gives impression worked).

another detail offset in case -03:00 because of system's default timezone. anyway, fix pattern , should work.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -