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时间元组,共 ...
随机推荐
- d3.js,初遇
接触d3完全是由兴趣所致,废话不多说看代码: var dataArray = [23, 13, 21, 14, 37, 15, 18, 34, 30];这是这个图所需要的数据,其实这个柱状图最初不长这 ...
- PDF转换成Word,ppt转换成word
pdf与word我没找到直接转换的方式,不过可以用间接方式嘛! pdf ==>picture ==>word!ppt转word的原理也是先把ppt转成图片,再把图片插入word! 先准备好 ...
- C语言面试题分类->排序算法
1.选择排序. 每次将最小的数,与剩余数做比较.找到更小的,做交换. 时间复杂度:O(n²) 空间复杂度:O(1) 优缺点:耗时但内存空间使用小. void selectSort(int *p,int ...
- [SQL]LeetCode175. 组合两个表 | Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- [Swift]LeetCode283. 移动零 | Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...
- [Swift]LeetCode539. 最小时间差 | Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minut ...
- [SQL]LeetCode626. 换座位 | Exchange Seats
SQL架构 Create table If Not Exists seat(id )) Truncate table seat insert into seat (id, student) value ...
- [Swift]LeetCode846. 一手顺子 | Hand of Straights
Alice has a hand of cards, given as an array of integers. Now she wants to rearrange the cards into ...
- the python challenge闯关记录(0-8)
0 第零关 2**38 = 274877906944 下一关的url:http://www.pythonchallenge.com/pc/def/274877906944.html 1 第一关 移位计 ...
- Tomcat相关面试题,看这篇就够了!保证能让面试官颤抖!
Tomcat相关的面试题出场的几率并不高,正式因为如此,很多人忽略了对Tomcat相关技能的掌握. 这次整理了Tomcat相关的系统架构,介绍了Server.Service.Connector.Con ...