I want to get the current time in the form of 14:42:49.901013+05:30
in python. Can anyone help me how can I do this?
Asked
Active
Viewed 849 times
0

the_unknown_spirit
- 2,518
- 7
- 34
- 56
-
Use [`datetime.strftime`](https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime). – Apr 08 '16 at 08:16
-
1@Selcuk The question does not ask about ignoring the TZ. – Apr 08 '16 at 08:17
-
@LutzHorn Yes, the question I linked is about _adding_ timezone to a naive datetime. – Selcuk Apr 08 '16 at 08:21
1 Answers
1
try this:
import pytz
from datetime import datetime
tz = pytz.timezone('Asia/Kolkata')
tz_now = datetime.now(tz)
print tz_now
>>> 2016-04-08 14:11:00.648000+05:30
You can convert it to string and split it to get time with timezone

Manish Gupta
- 4,438
- 18
- 57
- 104