![]() It gave us a new datetime object, pointing to a past timestamp i.e. Past Time as string object: 06-19-2021 20:57:09.436770įirst we fetched the current time using datetime.now() function and then subtracted 2 hours from the current time using timedelta. Read More Print a list without brackets in Python Current Time: 22:57:09.436770 You can pass the format string as argument and it will convert the datetime object to a string of the specified format. Step 4: If you want the final timestamp in string format, then convert the datetime object to string using strftime().It will give us a new datetime object, pointing to a new timestamp in past i.e. Step 3: Subtract the timedelta object from the datetime object pointing to current time.For that, pass the argument hours with value N in the timedelta constructor. Step 2: Create an object of timedelta, to represent an interval of N hours.It returns a datetime object pointing to the current time in local timezone. ![]()
0 Comments
Leave a Reply. |