总结的时间转换函数

# datetime时间转为字符串
def Changestr(datetime1):
str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S')
return str1 # 字符串时间转为时间戳
def Changetime(str1):
Unixtime = time.mktime(time.strptime(str1, '%Y-%m-%d %H:%M:%S'))
return Unixtime # datetime时间转为时间戳
def Changestamp(dt1):
Unixtime = time.mktime(time.strptime(dt1.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S'))
return Unixtime # 时间戳转为datetime时间
def Changedatetime(timestamp):
dt = datetime.datetime.fromtimestamp(timestamp)
return dt # uinx时间戳转换为本地时间
def Localtime(datetime1):
Localtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(datetime1))
return Localtime # 字符串时间转换函数
def Normaltime(datetime1):
Normaltime = datetime.datetime.strptime(datetime1,'%Y-%m-%d %H:%M:%S')
return Normaltime
1

Python字符串、时间戳、datetime时间相关转换的更多相关文章

  1. python字符串/列表/字典互相转换

    python字符串/列表/字典互相转换 目录 字符串与列表 字符串与字典 列表与字典 字符串与列表 字符串转列表 1.整体转换 str1 = 'hello world' print(str1.spli ...

  2. python 时间戳 datetime string 转换

    import datetime import time **datetime转时间戳** In [1]: now = datetime.datetime.now() In [2]: time.mkti ...

  3. Python时间、日期、时间戳之间的转换

    一.字符串与为时间字符串之间的互相转换 方法:time模块下的strptime方法 a = "2012-11-11 23:40:00" # 字符串转换为时间字符串 import t ...

  4. 使用python制作时间戳转换工具

    使用python制作时间戳转换工具 python 时间戳转日期 日期转时间戳 前言:作为一个程序员一般情况下,json和时间戳是常用的两个工具,我咨询过很多个朋友,他们一般都是通过在线工具对json进 ...

  5. python time和datetime的常用转换处理

    一.time 1.获取当前时间和时区 >>> now = time.time() # 当前时间 float类型 >>> time.strftime("%Y ...

  6. time,datetime,时间戳 时间格式转换

    总结: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) datetime.datetime.now().strftime( ...

  7. 【转】Python 字符串大小写转换

    转载自:python 中字符串大小写转换 一.pyhton字符串的大小写转换, 常用的有以下几种方法: 1.对字符串中所有字符(仅对字母有效)的大小写转换,有两个方法: print 'just to ...

  8. 转 Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)

    转自: http://www.cnblogs.com/huangcong/archive/2011/08/29/2158268.html 黄聪:Python 字符串操作(string替换.删除.截取. ...

  9. Python的字符串与字节码转换

    一张图弄懂python的字符串与字节码转换  

随机推荐

  1. 【LeetCode】217. Contains Duplicate (2 solutions)

    Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...

  2. Ubuntu菜鸟入门(十五)—— 安装aras2下载软件

    一.安装arias2 sudo add-apt-repository ppa:t-tujikawa/ppa sudo apt-get update sudo apt-get install aria2 ...

  3. Converting REF CURSOR to PIPE for Performance in PHP OCI8 and PDO_OCI

    原文地址:https://blogs.oracle.com/opal/entry/converting_ref_cursor_to_pipe REF CURSORs are common in Ora ...

  4. HTTP 请求头 Header

    HTTP 请求头 Header HTTP请求头概述 (HttpServletRequest) HTTP客户程序(例如浏览器),向服务器发送请求的时候必须指明请求类型(一般是GET或者POST或者HEA ...

  5. 【Android】Android实现监听返回键,主键(HOME),菜单键

    目录结构: contents structure [+] 简介 监听 返回键 监听 主键(Home键) 监听 菜单键 一.简介 本篇文章介绍如何在Android中实现监听返回键,主键,菜单键.一般情况 ...

  6. mongodb常用命令小结

    一.基于条件的查询 db.getCollection('monitor_log') .find({"requestUrl" : /app\/v1\/findcards\/cn/, ...

  7. EasyUI DataGrid Checkbox 多选 获取选中行中的内容

    <table id='grid' class='easyui-datagrid' style='width:950px;height:405px' url='Ajax-index.php?mod ...

  8. 豆瓣上9分以上的IT书籍-编程技术篇

    在豆瓣上9分以上的IT书籍-编程语言篇中,收集了很多优秀的编程语言书籍,也得到了不少读者的喜欢.不过也有一些读者留言说某某书为什么没有,一种是因为某些书并不算讲某种编程语言的,一种是由于豆瓣9分以上这 ...

  9. Asp.net(C#)常用正则表达式封装

    using System; using System.Collections; using System.Text.RegularExpressions; namespace MSCL { //// ...

  10. 常用DC-DC;AC-DC电源芯片

    求推荐几个常用的开关电源芯片http://bbs.21ic.com/icview-1245974-1-1.html(出处: 21ic电子技术论坛) 1.1 DC-DC电源转换器 1.低噪声电荷泵DC- ...