python 日期、时间
1、字符类型的时间 转为 时间数组
t1 = '2013-10-10 23:40:00'
timeArray = time.strptime(t1, "%Y-%m-%d %H:%M:%S")
# 结果如下
time.struct_time(tm_year=2013, tm_mon=10, tm_mday=10, tm_hour=23, tm_min=40, tm_sec=0, tm_wday=3, tm_yday=283, tm_isdst=-1)
2、字符类型的时间 转为其它显示格式
t2 = "2013-10-10 23:40:00"
# 转为数组
timeArray = time.strptime(t2, "%Y-%m-%d %H:%M:%S")
# 转为其它显示格式
otherStyleTime = time.strftime("%Y/%m/%d %H:%M:%S", timeArray)
print otherStyleTime # 2013/10/10 23:40:00
3、获取当前时间戳
# time获取当前时间戳
now = int(time.time())
timeArray = time.localtime(now)
转换成需要的格式
otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
4、datetime获取当前时间,数组格式
now = datetime.datetime.now()
print now
otherStyleTime = now.strftime("%Y--%m--%d %H:%M:%S")
def getlogname():
logfilename = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
return logfilename def getPresentTime():
now = datetime.datetime.now()
#print(now)
return now
python 日期、时间的更多相关文章
- Python日期时间函数处理
所有日期.时间的 api 都在datetime模块内. 1 日期的格式化输出 datetime => string import datetime now = datetime.datetime ...
- Python 日期时间处理模块学习笔记
来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...
- python 日期 & 时间
1. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 2. 时间间隔是以秒为单位的浮点小数. 3. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长 ...
- Python日期时间Date/Time
Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...
- 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码
本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...
- 1、Python 日期时间格式化输出
今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 import t ...
- python日期时间处理
time模块 #-*- coding: utf-8 -*- """ #获取当前时间的时间戳(单位秒) time.time() #推迟指定秒数后再运行 time.sleep ...
- python 日期时间处理
# 获取日期: import datetime #调用事件模块 today =datetime.date.today() #获取今天日期 deltadays =datetime.timedelta(d ...
- Python日期时间的相关操作
1.获取当前时间戳 import time t=time.time() print t 1459994552.51 #以秒为单位的 2.格式化日期 time.localtime() 返回当前时间的: ...
- Python日期时间函数
所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.n ...
随机推荐
- 【小技巧】【App store切换为中文】
为什么80%的码农都做不了架构师?>>> 贡献作者 -[XJDomain]博客XJ: https://my.oschina.net/shengbingli/blogGitHub ...
- [20170616]recover copy of datafile 6.txt
[20170616]no copy of datafile 6 found to recover.txt --//最近几天一直被这个问题纠缠,我虽然不知道问题在哪来,还是找到简单的解决方法,做1个记录 ...
- POJ 1170 Shopping Offers非状态压缩做法
Shopping Offers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5659 Accepted: 2361 Descr ...
- DP背包(一)
01背包 for(int i=0;i<n;i++) //遍历每一件物品 for(int j=v;j>=wei[i];j--)//遍历背包容量,表示在上一层的基础上,容量为J时,第i件物品装 ...
- P4932 浏览器(统计二进制1的个数)
P4932 浏览器 有\(n\)个数,\(x_1,x_2,\cdots,x_n\),问你有多少对\((u,v)\),使得\(x_u\operatorname{xor}x_v\)的二进制表示中有奇数个\ ...
- hue搭建
1.安装依赖: sudo yum -y install gcc-c++ asciidoc cyrus-sasl-devel cyrus-sasl-gssapi krb5-devel libxml2-d ...
- 带你看看Java的锁(一)-ReentrantLock
前言 AQS一共花了5篇文章,对里面实现的核心源码都做了注解 也和大家详细描述了下,后面的几篇文字我将和大家聊聊一下AQS的实际使用,主要会聊几张锁,第一篇我会和大家聊下ReentrantLock 重 ...
- Angular 从入坑到挖坑 - Router 路由使用入门指北
一.Overview Angular 入坑记录的笔记第五篇,因为一直在加班的缘故拖了有一个多月,主要是介绍在 Angular 中如何配置路由,完成重定向以及参数传递.至于路由守卫.路由懒加载等&quo ...
- SAP HTTP调用其他系统接口
1业务说明 ABAP系统通过HTTP方式调用其他系统发布的接口 2代码实现 2.1认证接口 根据访问的URL创建HTTP客户端 设置访问方式,并调用SEND和接收函数 有时需要专门验证用户名密码 获取 ...
- QTreeWidget更新后保存节点的展开状态
class Xx : public QWidget { Q_OBJECT struct ItemState{ ItemState(); int _id; bool _isExpend; }; publ ...