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. JS调用摄像头并上传图片到服务器

    本功能只能把图片转成base64码上传,如何上传图片还没有修改出来,有兴趣的朋友弄出来了,请给我留下言,谢谢了! 直接上代码,需要的朋友直接复制就可以使用了. <!DOCTYPE html> ...

  2. python深浅拷贝与赋值

    初学编程的小伙伴都会对于深浅拷贝的用法有些疑问,今天我们就结合python变量存储的特性从内存的角度来谈一谈赋值和深浅拷贝~~~ 预备知识一——python的变量及其存储 在详细的了解python中赋 ...

  3. linux命令排序

    sort -k1 -n 第一列按数字正排序 sort -K1 -rn 第一列按数字倒排序

  4. Javascript杂!

    JavaScript 标准参考教程(alpha) javascript中的 Object.defineProperty()和defineProperties JS压缩混淆  ---- 雅虎YUI 在线 ...

  5. ssh 登录报错 packet_write_wait: Connection to x.x.x.x port 22: Broken pipe

    问题 更新个人博客文章时遇到:Error: packet_write_wait: Connection to 192.30.253.113 port 22: Broken pipe packet_wr ...

  6. Confluence 6 € 欧元字符集不能正常显示

    € (euro) 标记 是一个 3 字节字符,在 (UTF-8)中这个字符被表示为 0xE2, 0x82, 0xAC. 有时候,你的系统中没有设置所有的地方为相同的字符集的时候(Confluence, ...

  7. SpringBoot集成前端模版(thymeleaf)

    1.在application.properties配置文件中添加 thymeleaf 的配置信息 spring.datasource.driverClassName=com.mysql.jdbc.Dr ...

  8. mysql where和having的区别

    简单描述:需要查询一个数量count,于是做分组查询后,发现有的数据没有过滤掉,于是就想加上过滤条件,就在group by后边写了where ,发现不好使,直接就报错了,查了一下,where只能写在g ...

  9. Nginx详解二十四:Nginx深度学习篇之灰度发布

    实战场景 - 灰度发布 灰度发布的作用:按照一定的关系区别,分部分的代码进行上线,使代码的发布能平滑过渡上线实现方式: 1.用户的信息cookie等信息区别 2.根据用户的IP地址 安装memcach ...

  10. Centos6.10部署TeamViewer

    1.在官网下载支持Linux系统的包,建议下载TeamViewer12的包,官网URL:https://www.teamviewer.com/cn/download/linux/ 2.将下载的软件包导 ...