python3中time模块与datetime模块的简单用法
__author__ = "JentZhang" import time # Timestamp 时间戳
print("Timestamp 时间戳:")
print(time.time())
print("#".center(50,"#")) # Structime 结构化时间
print("Structime 结构化时间:")
print(time.gmtime())
print(time.localtime())
print(time.struct_time)
print("#".center(50,"#")) # 格式化时间为能看得懂的格式
print("格式化时间为能看得懂的格式:")
print(time.strftime("%Y-%m-%d %X", time.localtime()))
print(time.strftime("%Y-%m-%d %X"))
print(time.strftime("%Y-%m-%d %H:%M:%S"))
print("#".center(50,"#")) import datetime # 计算3天前的当前时间
print("计算3天前的当前时间:")
time_str = (datetime.datetime.now() + datetime.timedelta(-3))
print(type(time_str))
print(time_str.strftime("%Y-%m-%d %H:%M:%S"))
# print(datetime.date)

python3中time模块与datetime模块的简单用法的更多相关文章
- python中time模块和datetime模块
time模块和datetime模块 时间分为三种模式(time 模块) 时间戳 (time.time()) 格式化字符串 (time.strftime(%Y-%m-%d %H:%M:%S %p)) ...
- Time模块和datetime模块
Time模块和datetime模块 一. 调用 import time #调用time模块 二.使用方法 1.time.time 拿到时间戳.以Linux诞生年份1970年开始计算到程序执 ...
- Python之路(第十六篇)xml模块、datetime模块
一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, xml比较早,早期许多软件都是用xml,至今很多传统公司如金融行业的很多系统的接口还主要 ...
- (转)python time模块和datetime模块详解
python time模块和datetime模块详解 原文:http://www.cnblogs.com/tkqasn/p/6001134.html 一.time模块 time模块中时间表现的格式主要 ...
- python time模块 sys模块 collections模块 random模块 os模块 序列化 datetime模块
一 collections模块 collections模块在内置的数据类型,比如:int.str.list.dict等基础之上额外提供了几种数据类型. 参考博客 http://www.pythoner ...
- python3 time模块与datetime模块
time模块 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平 ...
- 详解:Python2中的urllib、urllib2与Python3中的urllib以及第三方模块requests
在python2中,urllib和urllib2都是接受URL请求的相关模块,但是提供了不同的功能.两个最显著的不同如下: 1.urllib2可以接受一个Request类的实例来设置URL请求的hea ...
- python time模块和datetime模块详解
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- python time模块和datetime模块
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- day21 Pythonpython time模块和datetime模块详解
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
随机推荐
- [LeetCode] Score of Parentheses 括号的分数
Given a balanced parentheses string S, compute the score of the string based on the following rule: ...
- DOM-节点概念-属性
1.节点的概念 页面中的所有内容,包括标签,属性,文本(文字,空格,回车,换行等),也就是说页面的所有内容都可以叫做节点. 2.节点相关的属性 2.1.节点分类 **标签节点:**比如 div 标签, ...
- cadence电源和地平面的处理
覆铜是PCB布线的常用操作,下面总结覆铜的方法以及电源层分割的方法 PCB设计中,经常面临电源.地噪声的挑战,在高速数字系统中,电源和地的设计非常关键!电源和地的主要作用有: 一,为数字信号提供稳定的 ...
- Web发展史
Web 万维网常称为WWW(World Wide Web)发展至今仅30年,英国计算机科学家,蒂姆 伯纳斯 李爵士 提出了 World Wide Web的设计方案,1990年李爵士完成了Web 所有的 ...
- python语法_函数
---恢复内容开始--- 函数: 1 减少重复代码 2 定义一个功能,需要直接调用 3 保持代码一致性 def funcation_name(参数s): 功能代码块0 参数可以为多个,传入时按照前后 ...
- Python入门(青铜篇)
一.定义变量 print('hello world \n') 定义变量name='单宝梁' #定义字符串一定加‘’age=28 引号使用words="i'm 单宝梁" #字符串里有 ...
- WebGL绘制有宽度的线
WebGL中有宽度的线一直都是初学者的一道门槛,因为在windows系统中底层的渲染接口都是D3D提供的,所以无论你的lineWidth设置为多少,最终绘制出来的只有一像素.即使在移动端可以设置有宽度 ...
- [Swift]LeetCode232. 用栈实现队列 | Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- [Swift]LeetCode398. 随机数索引 | Random Pick Index
Given an array of integers with possible duplicates, randomly output the index of a given target num ...
- [Swift]LeetCode1013. 将数组分成和相等的三个部分 | Partition Array Into Three Parts With Equal Sum
Given an array A of integers, return true if and only if we can partition the array into three non-e ...