0

In neo4j I know how to get the current datetime as in now() with milliseconds precision, however I would like to be able to store microseconds or nanoseconds. Is there a way to achieve this via apoc, or adjusting my system time. I was reading about the 'limitations' of java Date and Calendar only storing .SSS ?

CREATE (l:LogEvent{
        eventID : 'I01'
        , dt : System.nanoTime({timezone:'UTC'})
        });
  • Does this answer your question? [Current time in microseconds in java](https://stackoverflow.com/questions/1712205/current-time-in-microseconds-in-java) – Ole V.V. Feb 16 '20 at 06:01
  • Thanks, hoping somebody would have found a workaround or pointed to something I had overlooked. – Jesperrekuh Feb 16 '20 at 16:06

1 Answers1

1

The temporal instants DateTime, LocalDateTime, Time, and LocalTime support the microsecond and nanosecond fields. Those fields can be set when using the appropriate temporal function to create an instant.

For example:

RETURN datetime({year:1984, month:11, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone:'Europe/Stockholm'})

In addition, if you have an epoch time with microsecond (or nanosecond) precision that you want to store, just break it down into 2 parts: its epoch seconds, and the remaining microseconds (or nanoseconds). With those 2 parts, you can create a DateTime as illustrated here (assuming secs, micros, and nanos are passed as parameters):

RETURN datetime({epochSeconds: $secs, microsecond: $micros})

or

RETURN datetime({epochSeconds: $secs, nanosecond: $nanos})
cybersam
  • 63,203
  • 6
  • 53
  • 76