#把datetime转成字符串
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d-%H") #把字符串转成datetime
def string_toDatetime(string):
return datetime.strptime(string, "%Y-%m-%d-%H") #把字符串转成时间戳形式
def string_toTimestamp(strTime):
return time.mktime(string_toDatetime(strTime).timetuple()) #把时间戳转成字符串形式
def timestamp_toString(stamp):
return time.strftime("%Y-%m-%d-%H", tiem.localtime(stamp)) #把datetime类型转外时间戳形式
def datetime_toTimestamp(dateTime):
return time.mktime(dateTime.timetuple())
#把时间戳转成datetime类型
import datetime,time t=int(time.time()) b=datetime.datetime.fromtimestamp(t) print(type(t),type(b))#<class 'int'> <class 'datetime.datetime'>

python datetime 字符串 时间戳的更多相关文章

  1. python datetime unix时间戳以及字符串时间戳转换

    将python的datetime转换为unix时间戳 import time import datetime dtime = datetime.datetime.now() ans_time = ti ...

  2. python datetime和unix时间戳之间相互转换

                                python datetime和unix时间戳之间相互转换 1.代码:    import time    import datetime # ...

  3. Python datetime 格式化字符串:strftime()

    Python datetime 格式化字符串:strftime()   Python 的datetime模块 其实就是date和time 模块的结合, 常见的属性方法都比较常用 比如: datetim ...

  4. python datetime date time详解

    之前一直被datetime,date,time弄的有点乱,可能是因为看文档每太看明白,找到了两篇文章供大家阅读都是转载的,其中有些名词这里解释一下: 世界协调时间(Universal Time Coo ...

  5. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  6. Python日期字符串比较

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 需要用python的脚本来快速检测一个文件内的二个时间日期字符串的大小,其实实现很简单,首先一些 ...

  7. Python 日期和时间戳的转换

    Python 日期和时间戳的转换 1. Python中处理时间的模块 Python中处理时间的模块有time.datetime和calendar. 在Python中表示时间的方式: 时间戳:10位整数 ...

  8. python datetime笔记

    python datetime笔记 http://mint-green.diandian.com/post/2011-09-09/4892024 获取当前时间,并通过字符串输出. 格式为:%Y-%m- ...

  9. python 时间字符串与日期转化

    python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...

随机推荐

  1. Spring 配置详解

    spring4配置文件详解 一.配置数据源 基本的加载properties配置文件 <context:property-placeholder location="classpath* ...

  2. python学习笔记(10)--组合数据类型(字典类型)

    理解映射: 映射是一种键(索引)和值(数据)的对应.字典是键值对的集合,键值之间无序.用大括号表示{},和dict()创建,键值对用冒号:表示. {键:值,键:值,键:值} >>> ...

  3. SpringBoot 标签之启动

    在SpringBoot中入口我们使用: package com.sankuai.qcs.regulation.traffic; import org.springframework.boot.Spri ...

  4. MySQL系列:索引基本操作(4)

    1. 索引简介 索引是一种特殊的数据库结构,可以用来快速查询数据中的特定记录. MySQL中索引包括:普通索引.唯一性索引.全文索引.单列索引.多列索引和空间索引等. 1.1 索引定义 索引由数据库表 ...

  5. 一、linux扩展

    1.linux-解压bz2文件提示tar (child): bzip2: Cannot exec: No such file or directory 原因,linux下没有bzip2解压工具 安装b ...

  6. LODOP打印安装到win的特殊字体

    LODOP能够打印的字体,来源于安装到本机windows里字体库的字体,如果需要打印特别的字体,需要在该操作系统安装.由于web网站的用户千差万别,字体库也有不同,但是一般常见的字体都是有的,因此做模 ...

  7. ES 6 系列 - 赋值的新方式:解构赋值

    变量的解构赋值 es 6 允许按照一定的模式,从数组和对象中提取值,然后对变量进行赋值,这被称之为解构: 一.数组的解构赋值 最基本写法: let [a, b, c] = [1, 2, 3]; a / ...

  8. asp.net—WebApi跨域

    一.什么是跨域? 定义:是指浏览器不能执行其他网站的脚本,它是由浏览器的同源策略造成的,是浏览器对JavaScript实施的安全限制. 同源策略限制了以下行为: 1.Cookie.LocalStora ...

  9. captive portal

    刷好lineageos后默认浏览器无法上网,实际上并不是没有连上网,而是captive portal即网关设置错误,设置一下即可上网. adb shell "settings put glo ...

  10. Visual Studio 2017 and Swagger: Building and Documenting Web APIs

    Swagger是一种与技术无关的标准,允许发现REST API,为任何软件提供了一种识别REST API功能的方法. 这比看起来更重要:这是一个改变游戏技术的方式,就像Web服务描述语言一样WSDL( ...