Python 日期与时间
2024-09-08 06:38:12
Python 3.6.4
import time, calendar, datetime print("距离1970年的秒数为:", time.time())
print("本地时间为:", time.localtime())
print("格式化:", time.asctime(time.localtime(time.time())))
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) # 输出
# 距离1970年的秒数为: 1518107142.14775
# 本地时间为: time.struct_time(tm_year=2018, tm_mon=2, tm_mday=9, tm_hour=0, tm_min=25, tm_sec=42, tm_wday=4, tm_yday=40, tm_isdst=0)
#格式化: Fri Feb 9 00:25:42 2018
# 2018-02-09 00:25:42
# 打印日历
print(calendar.month(, ))
# 下面是利用datetime输出时间,个人觉得比上面那种方法简单好用
i = datetime.datetime.now();
print(i)
print("格式化(年/月/日 时:分:秒):%s/%s/%s %s:%s:%s"
% (i.year, i.month, i.day, i.hour, i.minute, i.second)
)
# 以下为输出结果
March 2018
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
2018-02-09 00:25:42.179003
格式化(年/月/日 时:分:秒):2018/2/9 0:25:42
参考:http://www.runoob.com/python/python-date-time.html
最新文章
- ajax
- 了解HTML表单之13个表单控件
- QTableWidget控件总结<;一>;
- 【译】java.lang.ThreadLocal
- 检测当前运行环境——移动端与PC端。
- Codeforces Round #216 (Div. 2)解题报告
- javascript类,对象,实例
- Shell: extract more from listener.log(分析监听日志)
- oracle ed命令
- iOS_20_微博的骨架结构
- 为什么说Neutron不是SDN?
- 自己封装的一个js方法用于获取显示的星期和日期时间
- [Python Study Notes]计算cpu使用率v0.1
- 关于在spring boot里使用Thymeleaf模板的application.properties配置
- 2017-12-14python全栈9期第一天第二节之初始计算机系统
- Vue(六)过滤器
- 使用 Nuget安装DLL
- In-App Purchase iap 内付费 二次验证代码 (java 服务器端)
- FCC JS基础算法题(6):Truncate a string(截断字符串)
- MacOS 如何剪切文件