I am trying to truncate milliseconds from a UTC time zone. I have the code below where I am able to remove milliseconds but I still get the Z at the end. This outputs the following: ====Event date Time before truncate=== 2021-03-09T20:46:24.081Z ====Event date Time after truncate=== 2021-03-09T20:46:24Z Answer The Z is the timezone information. You can convert the OffsetDateTime
Tag: truncate
How can I truncate a double to only two decimal places in Java?
For example I have the variable 3.545555555, which I would want to truncate to just 3.54. Answer If you want that for display purposes, use java.text.DecimalFormat: If you need it for calculations, use java.lang.Math: