Reputation: 501
Silly Question, but couldn't find the proper answer. I converted my datetime object from UTC to ist using dateutils.
utc = datetime.utcnow()
UTC = tz.gettz('UTC')
indian = tz.gettz('Asia/Kolkata')
ind = utc.replace(tzinfo=UTC)
ind.astimezone(indian).replace(microsecond=0).__str__()
Output
'2019-07-30 16:32:04+05:30'
I would like to remove the +5:30 part, how do I go about doing that, except splitting the string on '+' symbol, or how do I avoid it being added in the first place.
Upvotes: 1
Views: 2234
Reputation: 23064
You can simply strip out the timezone from the datetime object by using tzinfo=None
. The string representation will still be ISO8601, but with no timezone offset part.
str(
datetime.now(tz=tz.gettz('Asia/Kolkata')))
.replace(microseconds=0, tzinfo=None)
)
# '2019-07-30 16:32:04'
Upvotes: 2