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. Maven安装与配置及使用

    下载及安装 官方下载地址:直达官网下载页面 进入下载页面后,根据你电脑所装jdk版本选择对应版本的maven进行下载. 我们可以看到该页上边红框内写明了,maven3.3版以上支持的是JDK1.7+的 ...

  2. MS SQL Server 建库建表

    CREATE DATABASE Test use Test --创建用户类型表CREATE TABLE UserType ( ID INT NOT NULL identity(1,1) primary ...

  3. Codeforces 438E The Child and Binary Tree [DP,生成函数,NTT]

    洛谷 Codeforces 思路 看到计数和\(998244353\),可以感觉到这是一个DP+生成函数+NTT的题. 设\(s_i\)表示\(i\)是否在集合中,\(A\)为\(s\)的生成函数,即 ...

  4. (转)整理 node-sass 安装失败的原因及解决办法

    转载地址:https://segmentfault.com/a/1190000010984731

  5. C# 中使用 Excel

    using System;using System.Collections.Generic;using System.Text;using System.Reflection;using System ...

  6. SS-QT5

    https://blog.csdn.net/sos218909/article/details/78781017

  7. 前端图片缓存之通过img标签加载GIF只能播放一次问题(转载)

    最近项目中要求再网页中插入一张gif图片,让用户每次到达该位置时动一次,所以我们就制作了一张只动一次的gif图片通过img标签引入.当用户进入该位置时,通过remove()清除图片然后重新append ...

  8. ipone mac真机调试

    safiri 识别不了iPhone 真机  需要在iPhone上 做设置  safri-> 高级 ->web检查器  进行设置,然后重新启动  safri即可...

  9. shell中的ps命令详解

    ps简介:Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的 ...

  10. dubbo源码之服务发布与注册

    服务端发布流程: dubbo 是基于 spring 配置来实现服务的发布的,对于dubbo 配置文件中看到的<dubbo:service>等标签都是服务发布的重要配置 ,对于这些提供可配置 ...