How do I compare two times to check if the server timestamp is working correctly?

Hello:

I am testing some package related API, in this API, I would get back a package, and there would be some time elements like I posted below, my goal is to test if the time server returned has happened in the past compared to the time the request was sent.

considering the time format, I used the Postman built-in faker library, and got the time, they seem to be to similar,

  • This is the response body time format:

  • This is the time format I got using Postman faker library

<2023-03-20T06:13:51.755Z>

when I tried to use Chai to assert (used expect object to compare the server response time stamp is β€œless than” current time (the time when the request was sent)

got failure.

Can someone give me some hint on what would be the best approach to compare these two dates?

PS: I can extract the year-month-day, and compare (possibly), but then it would not suffice to tell if the package created time was actually before I sent the request to the server about the server registered package created time.

i.e. the package on the server may have been created at 10AM, and I happened to send the request around 2PM on the same day, then just by comparing the year-month-day, I would not be able to tell if the server wrongly send some future time stamp.

Basically, I would like to be able to compare at least two dates (could be more as you can see from the screenshot), with current time which was created using faker library.

Thank you for your answer in advance.