coharness
2 years agoOccasional Contributor
Validate a time with allowance for seconds to be off
I have a label that reports the time and I am validating it. Usually it's ok, but sometimes the check is done a few seconds late, and so the label appears to be wrong. How could I allow for a few sec...
- 2 years ago
A simple solution would be to convert the time to Epoch, in seconds. If it's within the range of -/+2 seconds, then it's considered ok.
Pseudocode,
var reportTime = 1690908743 ... var currentTime = getTimeStamp() // 1690908745 if (reportTime >= (currentTime - 2)) and (reportTime <= (currentTime + 2)) { // reportTime is within range }