没有合适的资源?快使用搜索试试~ 我知道了~
dnxbjyj#jianshu-blog#python日期和时间的处理1
需积分: 0 0 下载量 55 浏览量
2022-07-25
14:30:02
上传
评论
收藏 4KB MD 举报
温馨提示
试读
准备常用操作输出当前的日期时间方式一:输出当前时间戳(单位:秒):方式二:格式化输出当前时间附:格式化字符串总结%a 英文星期简称%A 英文星期全称%b 英文月
资源推荐
资源详情
资源评论
总结一下python中对日期和时间的常用处理方法。
# 准备
```python
import time,datetime
```
# 常用操作
### 输出当前的日期时间
方式一:
```python
now = time.localtime()
print '【Output】'
print type(now)
print now
print now[:3]
```
【Output】
time.struct_time(tm_year=2017, tm_mon=8, tm_mday=21, tm_hour=23, tm_min=15, tm_sec=42, tm_wday=0, tm_yday=233, tm_isdst=0)
(2017, 8, 21)
输出当前时间戳(单位:秒):
```python
print '【Output】'
print time.time()
```
【Output】
1503329021.99
方式二:
```python
now = datetime.datetime.now()
print '【Output】'
print now.strftime('%Y-%m-%d %H:%M:%S')
```
【Output】
2017-08-21 23:23:46
### 格式化输出当前时间
```python
t = time.localtime()
print '【Output】'
print time.strftime('%Y-%m-%d %H:%M:%S',t)
time.sleep(2)
print time.strftime('%Y-%m-%d %H:%M:%S') # 如果不指定时间,输出的就是当前时间
```
【Output】
2017-08-21 23:17:57
2017-08-21 23:17:5
点击阅读更多
资源评论
柏傅美
- 粉丝: 21
- 资源: 325
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- CTF+pwn+nc(windows)+链接靶机
- AUTOSAR-SWS-MemoryDriver.pdf
- 链接器使用教程.docx.docx
- AUTOSAR-SWS-MemoryAccess.pdf
- AUTOSAR-SWS-MemoryAbstractionInterface.pdf
- AUTOSAR-SWS-FlashTest.pdf
- AUTOSAR-SWS-FlashEEPROMEmulation.pdf
- AUTOSAR-SWS-FlashDriver.pdf
- AUTOSAR-SWS-EEPROMAbstraction.pdf
- AUTOSAR-SRS-SPIHandlerDriver.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功