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 日期、时间的更多相关文章

  1. Python日期时间函数处理

    所有日期.时间的 api 都在datetime模块内. 1 日期的格式化输出 datetime => string import datetime now = datetime.datetime ...

  2. Python 日期时间处理模块学习笔记

    来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...

  3. python 日期 & 时间

    1. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 2. 时间间隔是以秒为单位的浮点小数. 3. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长 ...

  4. Python日期时间Date/Time

    Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...

  5. 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码

    本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...

  6. 1、Python 日期时间格式化输出

    今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 import t ...

  7. python日期时间处理

    time模块 #-*- coding: utf-8 -*- """ #获取当前时间的时间戳(单位秒) time.time() #推迟指定秒数后再运行 time.sleep ...

  8. python 日期时间处理

    # 获取日期: import datetime #调用事件模块 today =datetime.date.today() #获取今天日期 deltadays =datetime.timedelta(d ...

  9. Python日期时间的相关操作

    1.获取当前时间戳 import time t=time.time() print t 1459994552.51 #以秒为单位的 2.格式化日期 time.localtime() 返回当前时间的: ...

  10. Python日期时间函数

    所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.n ...

随机推荐

  1. HTML中使用CSS样式(下)

    上节内容回顾加补充: 补充:默认img标签,有一个1px的边框 如果点击图片跳转到连接,a标签下套img标签,在IE有的版本中,会有蓝色边框. <a href="http://blog ...

  2. webpack4.x下babel的安装、配置及使用

    前言 目前,ES6(ES2015)这样的语法已经得到很大规模的应用,它具有更加简洁.功能更加强大的特点,实际项目中很可能会使用采用了ES6语法的模块,但浏览器对于ES6语法的支持并不完善.为了实现兼容 ...

  3. Sunday算法:字符串匹配算法进阶

    背景 我们第一次接触字符串匹配,想到的肯定是直接用2个循环来遍历,这样代码虽然简单,但时间复杂度却是\(Ω(m*n)\),也就是达到了字符串匹配效率的下限.于是后来人经过研究,构造出了著名的KMP算法 ...

  4. springboot rabbitmq 找不到队列

    错误报告: org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$DeclarationException: Failed to ...

  5. electron-vue 运行项目时会报Electron Security Warning (Node.js Integration with Remote Content)警告

    使用electron-vue时,运行项目总会出现如下警告: 解决方法:在src/renderer/main.js中加入: process.env['ELECTRON_DISABLE_SECURITY_ ...

  6. MODIS系列之NDVI(MOD13Q1)七:时间序列S-G滤波之Python

    时间序列S-G滤波之Python 根据上上篇博文(MODIS系列之NDVI(MOD13Q1)五:NDVI处理流程)做出的NDVI.我们求NDVI时间序列图,但该NDVI时序图为地表各土地类型综合的ND ...

  7. Tarjan缩点割点(模板)

    描述:https://www.luogu.com.cn/problem/P3387 给定一个 nn 个点 mm 条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权 ...

  8. Linux查看redis占用内存的方法

    redis-cli auth 密码info # Memory used_memory:13490096 //数据占用了多少内存(字节) used_memory_human:12.87M //数据占用了 ...

  9. Spring官网阅读(十一)ApplicationContext详细介绍(上)

    文章目录 ApplicationContext 1.ApplicationContext的继承关系 2.ApplicationContext的功能 Spring中的国际化(MessageSource) ...

  10. 【HBase】快速了解上手rowKey的设计技巧

    目录 为什么要设计rowKey 三大原则 长度原则 散列原则 唯一原则 热点问题的解决 加盐 哈希 反转 时间戳反转 为什么要设计rowKey 首先要弄明白一点,Regions的分区就是根据数据的ro ...