Inconsistency in returning nanoseconds in /bin/date

I am using macOS’s /bin/date command, both in Terminal and via AppleScript (do shell script). I noticed inconsistent behaviour with the %N format specifier for nanoseconds: • On some Macs, date +%s%N returns numeric nanoseconds as expected. • On other Macs, the same command returns a literal N or fails when coerced to a number. • This occurs across different macOS versions and on both Intel and Apple Silicon machines.

My understanding is that macOS ships BSD date, which does not officially document %N. I am trying to determine: 1. Is %N in /bin/date officially supported on macOS, and if so, on which versions? 2. If %N is not supported, what is Apple’s recommended, portable method for obtaining sub-second or millisecond timestamps in shell scripts or AppleScript across all macOS versions?

Answered by DTS Engineer in 872528022
My understanding is that macOS ships BSD date

That’s generally a good way to approach issues like this, but in this case it seems that Apple has specifically added support for %N in recent OS releases, and documented it in date man page. AFAICT this landed in macOS 15. Certainly, it doesn’t work in 14.8.3 and does work in 15.6, which are the VMs I have handy.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

My understanding is that macOS ships BSD date

That’s generally a good way to approach issues like this, but in this case it seems that Apple has specifically added support for %N in recent OS releases, and documented it in date man page. AFAICT this landed in macOS 15. Certainly, it doesn’t work in 14.8.3 and does work in 15.6, which are the VMs I have handy.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Inconsistency in returning nanoseconds in /bin/date
 
 
Q