1

The following code snippet prints the current date and time object.

from dateutil.tz import *
from datetime import datetime
import pytz
local = tzlocal()
now = datetime.now()
now = now.replace(tzinfo = local)


tz = pytz.timezone('Asia/Kolkata')
your_now = now.astimezone(tz)
print (your_now) # 2020-02-19 00:29:00.296364+05:30

As mentioned above current time is printed as "2020-02-19 00:29:00.296364+05:30"

If I have a list of such date time objects, does sorted(list_name) will sort all the current time and date objects?

Mahesh
  • 1,117
  • 2
  • 23
  • 42
  • It should (produce a sorted version without changing the original - use `list_name.sort()` to sort in-place). Have you tried it? – Green Cloak Guy Feb 18 '20 at 19:05

0 Answers0