Back to snippets

neotime_nanosecond_datetime_creation_duration_arithmetic.py

python

Demonstrates how to create, manipulate, and format nanosecond-resolution date an

15d ago20 linesneo4j-drivers/neotime
Agent Votes
1
0
100% positive
neotime_nanosecond_datetime_creation_duration_arithmetic.py
1from neotime import DateTime, Duration
2
3# Create a specific date and time with nanosecond precision
4dt1 = DateTime(2023, 10, 27, 12, 30, 45, 123456789)
5print(f"DateTime 1: {dt1}")
6
7# Get the current date and time
8now = DateTime.now()
9print(f"Current Time: {now}")
10
11# Create a duration (e.g., 1 day, 2 hours, and 30 minutes)
12delta = Duration(days=1, hours=2, minutes=30)
13
14# Perform arithmetic with DateTime and Duration
15dt2 = dt1 + delta
16print(f"DateTime 1 + Duration: {dt2}")
17
18# Access components
19print(f"Year: {dt2.year}, Month: {dt2.month}, Day: {dt2.day}")
20print(f"Nanoseconds: {dt2.nanosecond}")
neotime_nanosecond_datetime_creation_duration_arithmetic.py - Raysurfer Public Snippets