I have a tick data as 638315425210000000 and 638338147200000000 need to add/subtract one milliseconds from it, and for the same I’m using the below specified code lines
let ticksInMilliseconds = 10000
//to add milliseconds to tick
const startTick = 638315425210000000
const millisecondsAdded = startTick + ticksInMilliseconds
//to reduce one millisecond
const endTick = 638338147200000000
const millisecondReduced = endTick - ticksInMilliseconds
For millisecondsAdded I get tick value as (638315425210010000) and for millisecondReduced get tick value as 638338147199990000
When converted to dates online to check if the milliseconds value are added/reduced the millisecondReduced gave correct value, but the millisecondsAdded still shows the same time with no milliseconds added 2023-09-29T00:02:01.000Z
I would like to understand why add is not adding millisecond to the tick and what should be the solution for the same
For conversion online I used https://tickstodatetime.azurewebsites.net/ which accepts the values I paste
2
Answers
your number is above the max safe integer value and operations aren’t reliable on integers at that point. You could use a Big integer to keep precision at that point
So testing this in Chrome on Win10, which allows such large numbers.
The code works if I actually subtract ticksInMilliseconds. You added in both cases.
HOWEVER the website you posted does not work on 10000 added.
638315425210000000 is 2023-09-29T00:02:01.000Z and 1 tick more is
638315425210010000 is 2023-09-29T00:02:01.000Z which is the same according to the site
Whereas
638338147200000000 is 2023-10-25T07:12:00.000Z and one tick less
638338147199990000 is 2023-10-25T07:11:59.999Z IS one millisecond less
I have raised an issue