Python datetime astimezone()方法与示例
Python datetime.astimezone()方法 (Python datetime.astimezone() Method)
datetime.astimezone() method is used to manipulate objects of datetime class of module datetime.
datetime.astimezone()方法用于操作模块datetime的datetime类的对象。
It uses an instance of the class and returns a datetime object with new tzinfo attribute tz. It works on a datetime class instance.
它使用该类的实例,并返回具有新tzinfo属性tz的datetime对象。 它适用于datetime类实例。
Module:
模块:
import datetime
Class:
类:
from datetime import datetime
Syntax:
句法:
astimezone(tz)
Parameter(s):
参数:
tz - timezone information which should be changed.
tz-应更改的时区信息。
Return value:
返回值:
Returns a datetime object with new tzinfo attribute tz.
返回具有新的tzinfo属性tz的日期时间对象。
Example:
例:
from datetime import datetime
import pytz
naive= datetime.now()
## Tzinfo is missing from the time object
## which is naive
print("Tzinfo:",naive.tzinfo)
print()
## Adding a timezone
timezone = pytz.timezone("Asia/Kolkata")
aware1 = naive.astimezone(timezone)
print("Tzinfo:",aware1.tzinfo)
print()
## After adding the timezone info,
## the object it becomes aware
timezone = pytz.timezone("Asia/Tokyo")
aware2 = aware1.astimezone(timezone)
print("Initial tzinfo:",aware1.tzinfo)
print("Final tzinfo:",aware2.tzinfo)
print()
## No timezone was defined for naive
print(naive)
## Timezone changed from None to Asia/Kolkata
## for aware1 object
print(aware1)
## Timezone changed from Asia/Kolkata to
## Asia/Tokyo for aware2 object
print(aware2)
Output
输出量
Tzinfo: None
Tzinfo: Asia/Kolkata
Initial tzinfo: Asia/Kolkata
Final tzinfo: Asia/Tokyo
2020-04-30 18:44:12.784666
2020-05-01 00:14:12.784666+05:30
2020-05-01 03:44:12.784666+09:00
翻译自: https://www.includehelp.com/python/datetime-astimezone-method-with-example.aspx
Python datetime astimezone()方法与示例相关推荐
- python forward(10)什么意思-Python turtle.forward方法代码示例
本文整理汇总了Python中turtle.forward方法的典型用法代码示例.如果您正苦于以下问题:Python turtle.forward方法的具体用法?Python turtle.forwar ...
- Python cv2.minMaxLoc方法代码示例
本文整理汇总了Python中cv2.minMaxLoc方法的典型用法代码示例.如果您正苦于以下问题:Python cv2.minMaxLoc方法的具体用法?Python cv2.minMaxLoc怎么 ...
- msvcrt python linux,Python msvcrt.CrtSetReportMode方法代码示例
# 需要导入模块: import msvcrt [as 别名] # 或者: from msvcrt import CrtSetReportMode [as 别名] def __enter__(self ...
- archlm检验python,Python sublime.arch方法代码示例
# 需要导入模块: import sublime [as 别名] # 或者: from sublime import arch [as 别名] def run(self): info = {} inf ...
- python datetime datetime_Python datetime.tzinfo方法代碼示例
本文整理匯總了Python中datetime.datetime.tzinfo方法的典型用法代碼示例.如果您正苦於以下問題:Python datetime.tzinfo方法的具體用法?Python da ...
- Python datetime isocalendar()方法与示例
Python datetime.isocalendar()方法 (Python datetime.isocalendar() Method) datetime.isocalendar() method ...
- 带有示例的Python datetime weekday()方法
Python datetime.weekday()方法 (Python datetime.weekday() Method) datetime.weekday() method is used to ...
- python的datetime举例_Python datetime模块的使用示例
1.获取当前年月日时分秒 # -*- encoding=utf-8 -*- import datetime now = datetime.datetime.now() print("now: ...
- c# datetime._C#| DateTime.AddTicks()方法与示例
c# datetime. DateTime.AddTicks()方法 (DateTime.AddTicks() Method) DateTime.AddTicks() method is used t ...
最新文章
- linux添加到普通用户sudo才干
- mysql更新数据索引慢_mysql添加索引,查询反而变慢
- java学习(163):同步方法锁
- 《Java8实战》笔记(16):结论以及Java的未来
- 李航老师亲自推荐的《统计学习方法》课件下载
- PyTorch | torch.full()使用方法 | torch.full()如何使用? torch.full()例子说明 | 通过torch.full创建全相同的张量
- 【Antlr】 Antlr 错误与恢复
- portal认证 php,如何用PHP制作OSSH 免费版华为Portal系统认证前端页面
- 她看:2021年95后女性人群洞察与媒体消费趋势前瞻.pdf(附下载链接)
- Object-C,NSSet,不可变集合
- linux中提示没有unzip命令解决方法
- python做鼠标自动移动_Python实现鼠标自动在屏幕上随机移动功能
- html大作业网页代码 web网页设计实例作业 ——二手书店-大学生书店(13页) 学生个人网站作业模板 简单个人网页制作
- python毕业设计总结范文大全_毕业设计心得体会范文3篇
- split 自动分割文件脚本
- 网易租赁服务器怎么添加组件,《我的世界》租赁服添加MOD教程 租赁服怎么添加小精灵MOD?...
- 漫威联手六位中国运动员致敬漫威电影宇宙十年
- 【树莓派】一、新坑入门-购买篇、基础配置篇
- Flutter-Container详解
- 【Python第一课】课程介绍
热门文章
- php 做更新进度条,PHP exec()后更新Bootstrap进度条
- 跨域产生的原因和解决方法_板式家具开料机加工过程产生崩边原因及解决方法...
- python句柄无效_subprocess.Popen 运行windows命令出现“句柄无效”报错的解决方法
- window.open不重复打开同一个名称的窗口_干货满满|Ctrl键的正确打开方式
- Java并发篇_线程详解
- git 命令 clone分支的代码
- Find the Difference(leetcode389)
- react 16.6 懒加载 Lazy 尝鲜
- ftp上传和下载命令
- Activity和Service交互