Skip to content

Instantly share code, notes, and snippets.

@martin-lukac
Created June 15, 2012 06:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martin-lukac/2935042 to your computer and use it in GitHub Desktop.
Save martin-lukac/2935042 to your computer and use it in GitHub Desktop.
India Timezone pytz possible issue
#!/usr/bin/python
import pytz
from datetime import datetime
intz = pytz.timezone('Asia/Kolkata')
nowdt = datetime.now(intz)
todaydt = datetime(2012,6,15,tzinfo=intz)
assert(todaydt.tzinfo == nowdt.tzinfo)
print todaydt
print nowdt
@lavishsaluja
Copy link

lavishsaluja commented Jun 18, 2019

I was facing this issue (below) while using pytz and datetime modules to print the current time in IST.

Traceback (most recent call last): File "/home/7f8865b29c9eb39ef5fed9ed458e8459.py", line 11, in <module> current_time = datetime.datetime.now(pytz.timezone('Asia / Calcutta')) File "/usr/lib/python3/dist-packages/pytz/__init__.py", line 170, in timezone raise UnknownTimeZoneError(zone) pytz.exceptions.UnknownTimeZoneError: 'Asia / Kolkata'

This function works fine in python:
def printTime(): current_time = datetime.datetime.now(pytz.timezone('Asia/Calcutta')) print ("The current time in india is : ") print (current_time)

You might also want to take a look at the different pytz timezones available at - pytz - time zones

@SachiYadav
Copy link

import datetime
import pytz
d_month = datetime.datetime.now(tz=pytz.timezone('Asia/Kolkata'))
print(d_month.strftime('%B %d, %Y'))

Hope this will be helpful.

@Tanay-dev
Copy link

Thanks for telling but can I write Delhi or Bangalore or Mumbai in place-off Kolkata

@SachiYadav
Copy link

SachiYadav commented Aug 17, 2020 via email

@Dernyt-TPE
Copy link

Thanks for telling but can I write Delhi or Bangalore or Mumbai in place-off Kolkata

Its the same for any. IST is taken from Kolkata only so No Problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment