Tanvi
Tanvi

Reputation: 413

Shorter and better way to find difference between timestamps

I have to delete a few tests I create if the timestamp on these are older than a week. On making a call to the API I get the created_at time stamps of all the tests in this format : 2014-08-04T04:49:28Z , 2014-08-04T04:49:22Z , etc.. It looks like a DateTime object but is a String actually. So firstly is there a way to convert this to a DateTime object?

I need to compare these against the current time and date and check whether they are older than a week or not. For this I know there are several ways but I wanted to know which one is the shortest and most efficient in scala without importing any java utility. Though Joda would have been helpful but the API response gives me String Thanks in advance!

Upvotes: 1

Views: 1372

Answers (1)

elm
elm

Reputation: 20405

Consider Scala wrappers for Joda (e.g GitHub /nscala-time ). It provides a rich API and avoids Java Date non thread-safety and mutability.

See What's the standard way to work with dates and times in Scala? Should I use Java types or there are native Scala alternatives? for further comments/discusison and usage examples.

Upvotes: 5

Related Questions