Home > Enterprise >  How to convert from string format of date (dd/mm/yyyy) to string format of date (yyyy-mm-dd'T&#
How to convert from string format of date (dd/mm/yyyy) to string format of date (yyyy-mm-dd'T&#

Time:03-21

I have to convert

"fromTime" : "04-10-2021"`

to

"fromTime" : "2021-10-04T00:00:00.000"

and

"toTime" : "06-10-2021"

to

"toTime" : "2021-10-06T23:59:59.000"

in java . Help please!

CodePudding user response:

Generally speaking, you really want to avoid representing date/time as String where ever possible.

Displaying date/time values to the user should be done in styles that respect their localisation and transmitting date/time values using JSON or XML should use common/standardised formats. This reduces a LOT of issues (don't even get me started)

For example, had I the choice, I would prefer to use ISO_LOCAL_DATE (uuuu-MM-dd) and ISO_LOCAL_DATE_TIME (uuuu-MM-dd'T'HH:mm:ss). I'm already worried about the lack of time zone information

  •  Tags:  
  • java
  • Related