-1

I am receiving a request having date time like

"modified" : "2021-06-11T07:56:53.494074Z"

And I am using

val df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")

With the above request I am getting the error

Conversion failed when converting date and/or time from character string.

If I am sending the request upto three digits after decimal it works example "modified": "2021-06-11T07:56:53.012Z" Is there a way to trim the request to milliseconds so that it woks or handle the extended request using SimpleDateFormat itself. Have already read many answers saying you cannot use SimpleDateFormat to handle nanoseconds So to use java.time package. Can someone please help with the trim or to support extended digits using SimpleDateFormat itself

1 Answers1

0

Try something like below.

new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.")

Append 'dot' after seconds it should drop nanoseconds.

Dinkar Kumar
  • 2,175
  • 2
  • 12
  • 22