Search code examples
phpunix-timestamp

get nanosecond timestamp in Unix epoch php


PHP strtotime gives unix timestamp, but how to get the nanosecond timestamp in unix epoch. I want to get it to store it in my influxdb.


Solution

  • PHP does not provide a function that has higher precision than microseconds, unfortunately. The UNIX timestamp, according to the standard, is stored in microseconds.
    However, there is a platform-dependent solution. Use

    system('date %N');

    on a linux machine. See man date or this page for more info.