Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time intervals
#8
I solved it, and the time stamps looks approximately difference by 1.01s, which I assume means there's 0.01s need for processing time. I'm assuming there's a better way to do time deltas, but for data logging, I think this would be ok, no?

from datetime import datetime
import time

print("\n*Timestamps*")

def time_stamps():
    return datetime.now()  # object to class datatime

x = time_stamps()
time.sleep(1)
y = time_stamps()
print(x)
print(y)

# Time Delays
    #time.sleep(1) # wait 1 second (s)
    #time.sleep(1/1000) # wait 1 millisecond (ms)
    #time.sleep(1/1000000) # wait 1 microsecond (us)
    #time.sleep(1 / 100000000)  # wait 1 nanosecond (ns)


if x > y:
    print("\ninstance 1 (x) is greater by: ",abs(x-y), "seconds")

else:
    print("\ninstance 2 (y) is greater by:", abs(x-y), "seconds")


print("\n*DATETIME attributes use *")
now = datetime.now()  # create an object to class datetime
print("today = ", now.date()) # returns year-month-day
print("month =",now.year) # year
print("year =",now.month) # month
print("day =", now.day) # day
print("hour =", now.hour) # hours
print("minute =", now.minute) # minutes
print("seconds =", now.second) # seconds
print("microseconds =", now.microsecond)  # microseconds


# print all attributes in class datetime
print("\n*DATETIME attributes use *")
for x in dir(datetime):
        print(x)
Reply


Messages In This Thread
time intervals - by project_science - Jan-30-2021, 09:32 PM
RE: time intervals - by bowlofred - Jan-30-2021, 09:44 PM
RE: time intervals - by project_science - Jan-30-2021, 10:07 PM
RE: time intervals - by bowlofred - Jan-30-2021, 10:50 PM
RE: time intervals - by project_science - Jan-30-2021, 11:01 PM
RE: time intervals - by bowlofred - Jan-30-2021, 11:38 PM
RE: time intervals - by nilamo - Feb-02-2021, 06:30 PM
RE: time intervals - by project_science - Feb-06-2021, 11:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting “simple” diagram with gridlines at specified intervals schniefen 1 3,281 Dec-03-2020, 05:54 PM
Last Post: schniefen
  Setting Tick Intervals In Sub Plots JoeDainton123 1 2,768 Oct-03-2020, 11:52 PM
Last Post: scidam
  Help Grouping by Intervals on list paul41 1 3,539 Dec-03-2019, 09:43 PM
Last Post: michael1789
  Grouping a list of various time into intervals paul41 1 5,197 Nov-24-2019, 01:47 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020