我比较新的蟒蛇

我有两个datetime对象.我需要计算它们之间的timedelta,然后以spcific格式显示输出.

Alpha_TimeObj = datetime.datetime(int(AlphaTime.strftime('%Y')), int(AlphaTime.strftime('%m')), int(AlphaTime.strftime('%d')), int(AlphaTime.strftime('%H')), int(AlphaTime.strftime('%M')), int(AlphaTime.strftime('%S')))

Beta_TimeObj = datetime.datetime(int(BetaTime.strftime('%Y')), int(BetaTime.strftime('%m')), int(BetaTime.strftime('%d')), int(BetaTime.strftime('%H')), int(BetaTime.strftime('%M')), int(BetaTime.strftime('%S')))

Turnaround_TimeObj = Beta_TimeObj - Alpha_TimeObj

这个Turnaround_TimeObj时间增量的一个例子是“2天,22:13:45”.

我想格式化输出,但不能这样做.

print Turnaround_TimeObj.strftime('%H hrs %M mins %S secs')

不起作用

我知道这样做的一种方法是将其转换为秒,然后将divmodding转换为获得所需的格式.

像在

totalSeconds = Turnaround_TimeObj.seconds

hours, remainder = divmod(totalSeconds, 3600)

minutes, seconds = divmod(remainder, 60)

print '%s:%s:%s' % (hours, minutes, seconds)

但我想知道我是否可以使用任何日期时间函数(如strftime)在单行中执行此操作.

编辑:实际转换为秒也不起作用.

如果我将时间增量“1天,3:42:54”转换为秒使用

totalSeconds = Turnaround_TimeObj.seconds

totalSeconds值显示为13374而不是99774. ie.它忽略了“天”的价值.

python timedelta 格式化_格式化python timedelta对象相关推荐

  1. python 时间序列预测_使用Python进行动手时间序列预测

    python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...

  2. python 概率分布模型_使用python的概率模型进行公司估值

    python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...

  3. python对象引用计数器_在Python中借助计数器对象对项目进行计数

    python对象引用计数器 前提 (The Premise) When we deal with data containers, such as tuples and lists, in Pytho ...

  4. 使用python预测基金_使用python先知3 1创建预测

    使用python预测基金 This tutorial was created to democratize data science for business users (i.e., minimiz ...

  5. python机器学习预测_使用Python和机器学习预测未来的股市趋势

    python机器学习预测 Note from Towards Data Science's editors: While we allow independent authors to publish ...

  6. python希腊字母字符串_#10 Python字符串

    前言 通过上一节可知,Python6个序列的内置类型中,最常见的是列表和元组,但在Python中,最常用的数据类型却不是列表和元组,而是字符串.要想深入了解字符串,必须先掌握字符编码问题.因此本篇博文 ...

  7. python笔记手册_《Python 学习手册》读书笔记

    Python 脚本首行 P72 #! /usr/local/bin/python or #! /usr/bin/env python Windows 上输入的技巧 P77 input() 函数防止双击 ...

  8. python视频点播系统_精通Python(微课视频版)/Python开发视频点播大系

    目录 第1篇 基础知识 第1章 Python概述 1.1 认识Python 1.1.1 Python的历史 1.1.2 Python的特点 1.1.3 Python的应用 1.2 搭建Python开发 ...

  9. python集群_使用Python集群文档

    python集群 Natural Language Processing has made huge advancements in the last years. Currently, variou ...

  10. python 打印类型_让Python输出更漂亮:PrettyPrinter

    PrettyPrinter是Python 3.6 及以上版本中的一个功能强大.支持语法高亮.描述性的美化打印包.它使用了改进的Wadler-Leijen布局算法,和Haskell打印美化库中的pret ...

最新文章

  1. 语言模型自然语言处理[置顶] 哥伦比亚大学 自然语言处理 公开课 授课讲稿 翻译(四)...
  2. Oracle查询表结构的一些相关语句
  3. mysql 存储过程 条件_mysql sql存储过程条件定义与处理
  4. python 选择多个文件夹_如何同时选择多个文件?
  5. 海驾学车过程全揭秘——第九篇:科目三集训及考试
  6. 程序员职业6个阶段,你处于哪个?
  7. java中paint_java中paint()的具体用法是什么?
  8. python模型训练框架_Pytorch-Transformers 1.0发布,支持六个预训练框架,含27个预训练模型...
  9. 温州近10%的网站存在高危安全漏洞
  10. LayaAir graphics 矢量绘图之直线、折线、曲线
  11. html 背景图片居中显示,CSS让背景图片居中显示的方法
  12. 数字孪生城市的2个技术关键点 优锘ThingJS
  13. Python入门随记
  14. xp计算机无法关机,WindowsXP电脑无法关机?6招轻松解决故障
  15. 彻底弄懂乒乓操作与并行化
  16. Eclips配置模板消息
  17. Angular中的指令(Directives)
  18. java版红石电路修改_我的世界红石数模互换电路【红石小课堂】
  19. 软考高项论文写作注意要点(一)
  20. arm linux免驱usb声卡,arm linux利用alsa驱动并使用usb音频设备

热门文章

  1. 苹果电脑双系统怎么切换 苹果电脑双系统的切换方法
  2. 如何搭建Java的开发环境
  3. 使用paddlehub给头像添加圣诞帽(GUI版)
  4. 创编游戏计算机课反思,大班音乐游戏教案及教学反思《包饺子》
  5. wireshark 导出rtpdump 并使用 ffmpeg播放
  6. html判断对象是否为空,javascript怎么判断对象是否为空对象?
  7. z7D3 安装linux,还在为装系统烦恼?战神Z7-SL7D3为你轻松搞定
  8. 初探苹果AppStore搜索指数及其含义,aso的搜索指数
  9. 【图像处理】【SEED-VPM】6.文件目录结构
  10. Android Wear开发步骤