python datetime 时区(timezone) dateutil
记录下python中的时区问题, 代码如下:
包括datetime.datetime对象使用不同的时区,以及在不同时区间转换。
from datetime import datetime from dateutil import tz, zoneinfo if __name__ == '__main__':
zonefile = zoneinfo.get_zonefile_instance()
print zonefile.zones.keys()[:20]
# use timezone
tz_dubai = tz.gettz('Asia/Dubai')
tz_sh = tz.gettz('Asia/Shanghai')
# Shanghai timezone
now_sh = datetime.now(tz=tz_sh)
print now_sh
# Dubai timezone
now_dubai = datetime.now(tz=tz_dubai)
print now_dubai
# datetime timezone conversion
print now_dubai.astimezone(tz_sh)
print 'done!'
结果:
['Atlantic/Canary', 'Europe/Lisbon', 'Etc/GMT+9', 'Etc/GMT+8', 'Antarctica/Mawson', 'Etc/GMT+3', 'Etc/GMT+2', 'Etc/GMT+1', 'Etc/GMT+0', 'Etc/GMT+7', 'Etc/GMT+6', 'Etc/GMT+5', 'Etc/GMT+4', 'Indian/Reunion', 'America/Fort_Nelson', 'Antarctica/Davis', 'America/Coral_Harbour', 'Asia/Dhaka', 'America/St_Lucia', 'Australia/LHI']
-- ::41.503000+:
-- ::41.503000+:
-- ::41.503000+:
done!
python datetime 时区(timezone) dateutil的更多相关文章
- python datetime时区转换
from pytz import timezone def datetime_as_timezone(date_time, time_zone): tz = timezone(time_zone) u ...
- python datetime学习
Python中处理时间的模块datetime, 这个模块里包含的类也叫datetime,所以要使用需要先import from datetime import datetime 获取当前日期和时间 d ...
- python datetime offset-aware与offset-navie相互转换
python datetime offset-aware与offset-navie相互转换 2016年11月13日 16:20:43 阅读数:2393 有时,我们使用python 的datetime模 ...
- Python3中datetime时区转换介绍与踩坑
最近的项目需要根据用户所属时区制定一些特定策略,学习.应用了若干python3的时区转换相关知识,这里整理一部分记录下来. 下面涉及的几个概念及知识点: GMT时间:Greenwich Mean Ti ...
- python datetime笔记
python datetime笔记 http://mint-green.diandian.com/post/2011-09-09/4892024 获取当前时间,并通过字符串输出. 格式为:%Y-%m- ...
- python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客
python datetime模块strptime/strptime format常见格式命令_施罗德_新浪博客 python datetime模块strptime/strptime form ...
- Python datetime.md
datetime datetime模块包含了一些用于时间解析.格式化.计算的函数. Times 时间值由time类来表示, Times有小时, 分, 秒和微秒属性. 以及包含时区信息. 初始化time ...
- python datetime和unix时间戳之间相互转换
python datetime和unix时间戳之间相互转换 1.代码: import time import datetime # ...
- Python datetime 格式化字符串:strftime()
Python datetime 格式化字符串:strftime() Python 的datetime模块 其实就是date和time 模块的结合, 常见的属性方法都比较常用 比如: datetim ...
随机推荐
- CF1100E
i207M给的题 省选前-小题解合集 给定一张有向图,每条边有边权.你可以花费边权的代价反转一条边,使得原图中没有环.最小化反转的边权的最大值. 首先二分,然后考虑判定. 转化为有些边可以翻转,有些边 ...
- [CTSC2016]时空旅行
description 题面 solution 线段树分治+斜率优化毒瘤题 题目可以简化为: 你要维护一个包含元素\((x,c)\)的集合 修改操作为从以前的一个版本更新,修改内容为添加或删除一个元素 ...
- [JOI 2014 Final] IOI 馒头
link 试题分析 我们发现若是要选馒头的话则应该从馒头售价高的先装. 并且若要选择包装盒时应该选择装x个最小的时候.所以只需要贪心$+$背包即可. #include<iostream> ...
- Codeforces 449.C Jzzhu and Apples
C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- shared_ptr & unique_ptr & weak_ptr (C++11)
c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...
- php优秀网摘
1.thinkphp的目录结构设计经验总结 说明:thinkphp3.2.3对类没有深刻的认识,对项目规模和架构有很糟糕的影响.这里写的目录结构和设计模式相当于对3.2添加了面向对象架构.第二个链接是 ...
- "Access restriction: The type BASE64Encoder is not accessible due to restrict"问题解决
问题如题: Eclipse中有一种叫做存取限制的机制,来防止你错误使用那些非共享的API.通常来说,Eclipse做的是对的,因为两点,我们不想要使用非共享API的,而且Eclipse知道什么是共享的 ...
- Debian9(8)下python3和python2同时安装如何使用pip
在bash下Python会调用python2.x python3会调用python3.x 如果使用pip install命令安装模块会安装python2的模块. 而python3的pip命令使用的是p ...
- ECNA-A- Abstract Art
题目描述 Arty has been an abstract artist since childhood, and his works have taken on many forms. His l ...
- 【BZOJ做题记录】07.07~?
在NOI一周前重开一个坑 最后更新时间:7.08 07:38 7.06 下午做的几道CQOI题: BZOJ1257: [CQOI2007]余数之和sum:把k mod i写成k-k/i*i然后分段求后 ...