# Nanosecond epoch time - POSIXClock.jl refresh

**URL:** https://discourse.julialang.org/t/nanosecond-epoch-time-posixclock-jl-refresh/48321
**Category:** General Usage
**Tags:** posix, clock
**Created:** [October 13, 2020, 10:15pm UTC](https://discourse.julialang.org/t/nanosecond-epoch-time-posixclock-jl-refresh/48321 "2020-10-13T22:15:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [October 13, 2020, 10:15pm UTC](https://discourse.julialang.org/t/nanosecond-epoch-time-posixclock-jl-refresh/48321/1 "2020-10-13T22:15:51Z")

</div>

These are just notes on updating from a conversation on Slack:

> **[Slack is your productivity platform](https://julialang.slack.com/?redir=%2Farchives%2FC6A044SQH%2Fp1602610636475300)**
>
> Slack is a new way to communicate with your team. It’s faster, better organized, and more secure than email.

> **[GitHub - ibadr/POSIXClock.jl: Julia bindings for POSIX Clock](https://github.com/ibadr/POSIXClock.jl)**
>
> Julia bindings for POSIX Clock. Contribute to ibadr/POSIXClock.jl development by creating an account on GitHub.

```julia
const librt = Sys.isunix() ? Libdl.find_library(["librt.so"]) : nothing
mutable struct Clock{IsUnix}
    sec::Int
    nsec::Int
end
function Clock()
    return Clock{Sys.isunix()}(0,0)
end
const GlobalClock = Clock()
function get_time(c::Clock{true})::Int
    ccall((:clock_gettime, librt), Int32, (Int32, Ptr{Clock}), Int32(0), pointer_from_objref(c))
    return c.sec * 1000000000 + c.nsec
end
function get_time(::Clock{false})::Int
    return round(Int,time() * 1e9)
end
# not thread safe to use GlobalClock so be careful
function get_time()
    return get_time(GlobalClock)
end

```
