Date&#x2F;Time is a fine example of something that initially seems simple, but turns out to be exceedingly complex at times. For this reason, I usually use a proper library (like Joda Time for Java, Moment.js for JavaScript, though Java 8 has improved things a lot with the built-in APIs) when dealing with any date&#x2F;time data, especially when manipulating it, i.e. finding out a duration between two dates, adding a duration to a date, etc.<p>Also, it&#x27;s helpful if you have some sort of DateService that you can mock rather than using something like &quot;new Date()...&quot; in your code. The article touches on this; in general you should not have tests that rely on or deal with the current datetime as that&#x27;s just asking for non-deterministic behaviour. By having your code call out to a DateService to get the current date-time, rather than creating it on its own, unit testing becomes easier.<p>My favourite date&#x2F;time story: 
<a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6841333&#x2F;why-is-subtracting-these-two-times-in-1927-giving-a-strange-result" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6841333&#x2F;why-is-subtractin...</a>