File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ author : ameyjadiye
3
+ layout : post
4
+ title : " Timezone conversion in python -Easy way"
5
+ date : 2014-08-08 19:17
6
+ comments : true
7
+ tags :
8
+ - python
9
+ ---
10
+
11
+ This lib i found most usefulll [ python-dateutil] ( http://niemeyer.net/python-dateutil ) .
12
+ ``` bash
13
+ sudo pip install python-dateutil
14
+ ```
15
+
16
+ {% highlight python %}
17
+ from datetime import datetime
18
+ from dateutil import tz
19
+ date_str = "2014-08-08 19:18:01"
20
+ fmt="%Y-%m-%d %H:%M:%S"
21
+ from_zone = tz.gettz('UTC')
22
+ to_zone = tz.gettz('America/New_York')
23
+
24
+ utc = datetime.strptime(date_str, fmt)
25
+ utc = utc.replace(tzinfo=from_zone)
26
+ print utc.strftime(fmt)
27
+ # Convert time zone
28
+ central = utc.astimezone(to_zone)
29
+ print central.strftime(fmt)
30
+ {% endhighlight %}
31
+
32
+ Happy coding ..... :)
You can’t perform that action at this time.
0 commit comments