How to get nanosecond uint64 timestamp in C++ using chrono

Use this code to get the nanosecond timestamp using std::chrono

#pragma once
#include <chrono>
#include <cstdint>

inline uint64_t NanosecondNow() {
    auto now = std::chrono::system_clock::now();
    auto duration = now.time_since_epoch();
    auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
    return static_cast<uint64_t>(nanoseconds.count());
}