# Dates.Time Parsing a Time String with Nanosecond Resolution

**URL:** <https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540>\
**Category:** New to Julia\
**Tags:** dates\
**Created:** [October 29, 2023, 3:45pm UTC](https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540 "2023-10-29T15:45:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnDuffy](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JohnDuffy](https://discourse.julialang.org/u/JohnDuffy)\
**Post date:** [October 29, 2023, 3:45pm UTC](https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540/1 "2023-10-29T15:45:21Z")

</div>

Hi

Julia 1.9.3 MacOS x86\_64

As I understand the Dates documentation, the resolution for a DateTime object is milliseconds and for a Time object it is nanoseconds.

So, I believe I should be able to parse a nanosecond time string into a Time object, but I’m struggling with this.

For example, this works…

julia\> t = parse(Time, “00:00:00.123”)  
00:00:00.123  
julia\> t  
00:00:00.123  
julia\> t.instant  
123000000 nanoseconds

But, I can’t get this to work…

parse(Time, “00:00:00.123456789”)  
ERROR: ArgumentError: Unable to parse date time. Expected directive DatePart(s) at char 10

I’ve tried various DateFormat strings, but none seem to work.

An example in julia/stdlib/Dates/test/io.jl with finer resolution than milliseconds would be helpful.

Kind regards

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [October 29, 2023, 6:13pm UTC](https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540/2 "2023-10-29T18:13:08Z")

</div>

There’s a longstanding [open issue](https://github.com/JuliaLang/julia/issues/37579) for this. You could do something like this as a workaround:

```julia
julia> function ns_time(t_str)
           t_s, t_frac = split(t_str, '.')
           Time(t_s) + Nanosecond(rpad(t_frac, 9, '0'))
       end
ns_time (generic function with 1 method)

julia> ns_time("00:00:00.123")
00:00:00.123

julia> ns_time("00:00:00.123456789")
00:00:00.123456789

```

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [October 29, 2023, 6:18pm UTC](https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540/3 "2023-10-29T18:18:59Z")

</div>

> **[GitHub - JuliaTime/NanoDates.jl: Dates with nanosecond resolved days](https://github.com/JuliaTime/NanoDates.jl)**
>
> Dates with nanosecond resolved days. Contribute to JuliaTime/NanoDates.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![JohnDuffy](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JohnDuffy](https://discourse.julialang.org/u/JohnDuffy)\
**Post date:** [October 29, 2023, 7:34pm UTC](https://discourse.julialang.org/t/dates-time-parsing-a-time-string-with-nanosecond-resolution/105540/4 "2023-10-29T19:34:55Z")

</div>

Thank you all. I will give NanoDates a try.
