1、获取当前时间戳

float_time = time.time()

2、格式化当前时间

#格式化当前时区时间
now_time = time.strftime('%Y-%m-%d %H:%M:%S')
print(now_time)

3、时间戳转时间

#时间戳转为本地时间
local = time.localtime(1505284047.1286137)
#时间戳转格林尼治时间
local_s =time.gmtime(1505284047.1286137)
pub_st = time.strftime('%Y-%m-%d %H:%M:%S',local_s)
pub_time = time.strftime('%Y-%m-%d %H:%M:%S',local)
print(pub_time,pub_st)

4、字符串转时间

#字符串转化为时间戳
#pub_time为时间字符串 time_str为time类型的时间
time_str = time.strptime(pub_time,'%Y-%m-%d %H:%M:%S')
#ss为时间戳
ss = str(time.mktime(time_str))
#sss为格式化时间
sss = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(float(ss)))
print(time_str,ss,sss)

5、%b表示英文缩写月份

hj =  '31 Jul 2008'
time_str = time.strptime(hj,'%d %b %Y')
ss = str(time.mktime(time_str))
sss = time.strftime('%Y-%m-%d',time.localtime(float(ss))) print(time_str,sss)

6、英文对应月份字典

time_dict = {'January':'','February':'','March':'','April':'','May':'',
'June':'','July':'','August':'','September':'','October':'','November':'','December':''}

python3对于时间的处理的更多相关文章

  1. 【转】Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  2. Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  3. Python3之时间模块详述

    Python3之时间模块  time & datetime & calendar 一. 概述 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多p ...

  4. Python3之时间模块time & datetime & calendar

    一. 简介 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多python函数用一个元组装起来的9组数字处理时间. python中时间日期格式化符号: %y 两位 ...

  5. python3的时间日期处理

    1.python3日期和时间 Python 程序能用很多方式处理日期和时间,转换日期格式是一个常见的功能. Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时 ...

  6. python3 mysql 时间参数错误

    一.环境 mac OS + python3.6 + pymysql 二.执行 1.语句 select count(user_id) from chezhubangapppp.yfq_user wher ...

  7. python3 根据时间获取本月一号和月末日期

    一.概述 有一个统计报表需求,需要知道上个月的第一天和最后一天,来进行上个月的数据统计. 二.代码实现 #!/usr/bin/env python3 # coding: utf-8 import ca ...

  8. Python3对时间模块的操作

    python中使用time和datetime来进行时间操作 import time import datetime # 获取时间戳 time.time() # 1544601181.549864 # ...

  9. python3 datetime 时间格式相减 计算间隔

    info_rent = MysqlUtils.select_yezhu_rent() info_sale = MysqlUtils.select_yezhu_sale() now_time = dat ...

随机推荐

  1. 【原创】Linux基础之Shell脚本常用命令

    #!/bin/sh 1 取脚本参数 $# 参数个数$0 当前脚本名$1 第1个参数$n 第n个参数$* 所有参数$@ 所有参数$? 上个命令的状态$$ 当前pid 2 日期 $ dateWed Mar ...

  2. python 启动虚拟环境

    假设你有两个Python项目-A和B,这两个项目都需要使用同一个第三方模块-tensorflow.如果这两个项目使用相同的tensorflow版本,也许不会有什么问题. 但是,当A和B项目使用不同的t ...

  3. 大数据mapreduce俩表join之python实现

    二次排序 在Hadoop中,默认情况下是按照key进行排序,如果要按照value进行排序怎么办?即:对于同一个key,reduce函数接收到的value list是按照value排序的.这种应用需求在 ...

  4. C# Excel行高、列宽、合并单元格、单元格边框线、冻结

    private _Workbook _workBook = null;private Worksheet _workSheet = null;private Excel.Application _ex ...

  5. Confluence 6 数据库整合的限制

    数据库整合的限制 注意: Confluence 自带的 XML 方式导出方法并不适用于备份和整合大数据集.这里有一些第三方的数据库工具你可以使用能够帮助你对大数据集进行备份和整合.如果你在选择正确工具 ...

  6. Confluence 6 布局高级自定义

    重载 Velocity 模板 velocity 目录是 Confluence Velocity 模板文件进行搜索时候需要的文件夹.例如,你可以通过将你的 Velocity 文件使用正确的文件名放置到正 ...

  7. 【python】控制台输出颜色

    来源:http://www.cnblogs.com/yinjia/p/5559702.html 在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端 ...

  8. WampServer & XAMPP Configure with MariaDB and MySQL

    第一部分补上次的一个问题 1.WampServer 3不支持的硬件格式 FAT3和 exFAT 他只能工作在NTFS的格式硬盘上. 不能在Windows XP上运行. 安装 WampServer 必须 ...

  9. lightoj1234 打表技巧:分块打表

    /* 打不了那么大的表,所以只记录分块的信息即可 */ #include<bits/stdc++.h> using namespace std; #define maxn 1000005 ...

  10. h5 video标签的使用

     标签的布置 <video src="1.mp4" poster="1.jpg" id="vid" controls> 你的浏览 ...