0

When I convert this String to TimeStamp by using the method TimeStamp.valueOf(string), it adds '.0' at the end of TimeStamp. However I want it in the same format as of string but the data type should be TimeStamp.

String myStr = "2021-08-25 09:46:26";
TimeStamp dateTime = TimeStamp.valueOf(mystr);

returns 2021-08-25 09:46:26.0

I've also tried SimpleDateFormat with pattern "yyyy-MM-dd HH:mm:ss", but it also ruins the format.

coco-candy
  • 13
  • 4
  • Then you will have `0` milliseconds, because that is how a `TimeStamp` records time. At the millisecond level. And with that format. And you cannot change it. – Elliott Frisch Aug 28 '21 at 15:06
  • The standard library does not support a formatted Date-Time object. You can get a formatted `String` value using a formatter. – Arvind Kumar Avinash Aug 28 '21 at 15:09

0 Answers0