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 ...
随机推荐
- webpack插件解析:HtmlWebpackPlugin是干什么的以及如何使用它
HtmlWebpackPlugin是一个出现频率比较高的webpack插件,本文对其作用和配置作一番比较详细的分析(本文的配置均在webpack.config.js中进行). 为何使用它 简单来说,H ...
- Express 文档(常见问题)
常见问题 我该如何构建我的应用程序? 这个问题没有明确的答案,答案取决于你的应用程序规模和所涉及的团队,为了尽可能灵活,Express在结构方面没有做出任何假设. 在你喜欢的任何目录结构中,路由和其他 ...
- ZLEXCOUNT key min max
1 简介 ZLEXCOUNT 命令用于计算有序集合中指定成员之间的成员数量. 2 语法 2.1 完整示例 zlexcount zset [member1 [member5 2.2 说明 指令 是否必须 ...
- Pointers and Memory
Stanford CS Education Library #102 一.Basic Pointers 指针主要有两个用途:使不同的代码段共享信息.方便链表(树)的处理. 指针示意图: derefer ...
- 数学--数论--HDU 2136(素数筛选法)
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- 图论--传递闭包(Floyd模板)
#include<iostream> #include<cstring> #include<cmath> using namespace std; int dp[1 ...
- python(安装)
1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python3(建议自定义安装路径) 3.配置环境变量 [右键计算机]-->[属 ...
- Keepalived搭建LVS高可用性集群系统
! Configuration File for keepalived global_defs { notification_email { acassen@firewall.loc failover ...
- 支付宝小程序云开发(Serverless)
支付宝小程序云开发(Serverless) 博客说明 文章所涉及的资料来自互联网整理和个人总结,意在于个人学习和经验汇总,如有什么地方侵权,请联系本人删除,谢谢! 一.在支付宝账号里面开通小程序云服务 ...
- SPFA+链式前向星
板子 #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll inf=2<<3 ...