[Python模块学习]timeago模块
来源:互联网 发布:java多线程调用方法 编辑:程序博客网 时间:2024/05/16 17:44
timeago模块
功能描述:计算两个不同时间的时间差,并将时间差转换为文字描述。
安装:pip install timeago
这个模块只有一个方法format()
,包括三个参数:date、now和locale,返回经过格式化的字符串。
date参数代表将被格式化的时间。可为datetime实例、timedelta实例或者时间字符串(yyyy-MM-dd hh:mm:ss或者yyyy/MM/dd hh:mm:ss)。
now参数代表被参照的时间。类型同上。
也就是说:”相对于now,date是…“的意思。(总感觉这样命名好绕口)
最后一个参数locale代表语言设置,可为en(英文)或者zh_CN(中文),也可在locale.py文件里自行添加别的语言。
代码示例:
import timeago, datetimenow = datetime.datetime.now()date = datetime.datetime.now() + datetime.timedelta(hours = 3)print(timeago.format(date, now, "zh_CN")) # print '3小时后'
该模块由一位国人提供,github地址为:timeago。同时还有一个:timeago javascript版。
感谢内容提供者。
以上内容遵循BY-NC-SA协议,欢迎转载,转载请注明作者。
1 0
- [Python模块学习]timeago模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python模块学习-os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- [Python模块学习] glob模块
- Python 模块学习:os模块
- Python 模块学习:os模块
- Python模块学习:sys模块
- Chapter 10.1 Variational Inference <Pattern Recognition and Machine Learning>
- 指令系统
- AOE网上的关键路径
- linux 简单目录操作
- Android studio 的安装_2016.08.19
- [Python模块学习]timeago模块
- Vagrant: 一致性开发环境创建利器
- Vive开发之VR射箭
- J2se源码剖析 基本数据类型Integer
- Linux之索引节点inode(index node)
- jvm 指令集代码
- BZOJ 4653: [Noi2016]区间
- BigDecimal使用技巧
- Linux之文件通配符