Programmatically get boot time on macOS

Want to know the system uptime on macOS? As in every UNIX we can’t rely on /proc/uptime- there isn’t a /proc filesystem at all!

We should use sysctl instead:

sysctl kern.boottime # kern.boottime: { sec = 1519371175, usec = 996342 } Fri Feb 23 09:32:55 2018

If we want to know all the available keys accepted by sysctl, we can pass -a:

sysctl -a

Thank you, StackOverflow!