# Parsing Nanosecond Timestamps into DateTime

**URL:** https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302
**Category:** New to Julia
**Created:** [June 6, 2022, 11:39am UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302 "2022-06-06T11:39:49Z")
**Posts on this page:** 5
**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: [June 6, 2022, 11:39am UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302/1 "2022-06-06T11:39:49Z")

</div>

Hi

I receive streamed JSON data with nanosecond precision timestamps. I don’t need nanosecond precision for my application, millisecond precision is good enough, but I’m struggling to parse my timestamp string into a DateTime…

This works using a regular expression:

```julia
re = r"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3})\d{6}Z"
m = match(re, "2022-01-01T00:00:00.002000001Z")
time = DateTime(m[1])

```

And this works using SubString():

```julia
time = DateTime(SubString("2022-01-01T00:00:00.002000001Z", 1, 23))

```

But I would like to use the following as it seems more succinct and clear:

```julia
time = DateTime("2022-01-01T00:00:00.002000001Z", dateformat"NEED_HELP_HERE")

```

I have tried lots of combinations of the format string but I can’t seem to get it right.

Any help would be very much appreciated.

Regards

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [June 6, 2022, 1:01pm UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302/2 "2022-06-06T13:01:53Z")

</div>

You could try just parsing them to the nanosecond precision using a package like [GitHub - JuliaTime/NanoDates.jl: Dates with nanosecond resolved days](https://github.com/JeffreySarnoff/NanoDates.jl) and then truncating to millisecond?

---

<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: [June 11, 2022, 4:35pm UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302/3 "2022-06-11T16:35:24Z")

</div>

Thank you, I will give that a try.

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [June 11, 2022, 10:30pm UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302/4 "2022-06-11T22:30:03Z")

</div>

Hi John,

NanoDates.jl is to be introduced with a lightning talk at JuliaCon.  
I have planned for an initial release some weeks earlier. Meanwhile, the package and the presentation are working in collaboration with Julia for our benefit.

[TimesDates.jl](https://github.com/JeffreySarnoff/TimesDates.jl) is our current answer to your question. As a package in wide use it has been stable and, to the best of our knowledge, computing correctly for a good while. When [NanoDates.jl](https://github.com/JeffreySarnoff/NanoDates.jl) is official, it offers more flexible use. However, it is not going to include timezone support.

As you have questions, please ask them here.

---

<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: [June 15, 2022, 8:10am UTC](https://discourse.julialang.org/t/parsing-nanosecond-timestamps-into-datetime/82302/5 "2022-06-15T08:10:41Z")

</div>

Thank you Jeffrey

Looking forward to NanoDates release and the lightning talk.

Kind regards
