For my purpose, which I simply need different timestamps to distinguish different entries, this is good enough for me. it doesn't seems to matter as my computer cannot even print at a speed that high. I am not sure how 'accurate' it really is, but the resolution is at least higher. Print('time.perf_counter(): ', datetime0 + timedelta(0, time.perf_counter()-t0)) Print('datetime.now(): ', datetime.now()) I compared it with using time.perf_counter() and adding to the starting datetime ''' nonce str(uuid4()) time datetime.now() newnonce Nonce(idnonce, timestamptime) session. Why does that happen? Is there any way that I can get an accurate timestamp down to the microsecond? Actually I don't need microseconds, but it would be nice to get 0.1ms resolution. def createnonce(session: Session) -> str: ''' Create a one time use nonce valid for a short time for user authentication. Try the following demonstrations using our Online Interpreter. It returns your local date and time defined by the module. import datetime About Python Datetime.now () The function now allows us to get the current date and time. Round off and convert the timestamp in integer to get the integer timestamp. Convert the datetime object into timestamp using datetime.timestamp () method. And then import the pytz library to instantiate the timezone object to localize the datetime. However, I always get something like that. As of Python 3.10, datetime is part of the Python Standard Library under the Data Types category. First, we get the current time using (). Since it supposes to output in microsecond, I expected that each print will be different. I was testing the resolution of datetime.now().
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |