osx - Using SHELL BSD "date" command for conversion to Nanoseconds? -


i need convert time nanoseconds, bsd date command isn't suitable, best can returns seconds.. date +"%h:%m:%s" returns 17:33:07..

seems there difference between mac's bsd date version, , linux gnu one. last 1 can return nanoseconds. first can't..

should using python or ruby scripts instead of shell? or there solution nanoseconds on mac?

no in fact no %n

the osx date command doesn't nanonseconds, in osx can still system.

for example, in c, should system uptime:

#include <inttypes.h> #include <stdio.h> #include <stdint.h>  #include <mach/mach_time.h>  int main(void) {         uint64_t t = mach_absolute_time();          // ratio between mach_absolute_time units , nanoseconds.         mach_timebase_info_data_t data;         mach_timebase_info(&data);          // convert nanoseconds.         t *= data.numer;         t /= data.denom;          printf("%" priu64 "\n", t);          return 0; } 

save uptimens.c, run make uptimens shell.

mac:~ ghoti$ ./uptimens 366181198555774 mac:~ ghoti$  

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -