import datetime
import time

**datetime转时间戳**

In [1]: now = datetime.datetime.now()
In [2]: time.mktime(now.timetuple())
Out[2]: 1433501775.0

**datetime转string**

In [3]: now.strftime('%Y-%m-%d')
Out[3]: '2015-06-05' In [4]: type(now.strftime('%Y-%m-%d'))
Out[4]: str

**string转datetime**

In [5]: time_str = '2015-05-01 12:00:01'

In [5]: date_time = datetime.datetime.strptime(time_str,'%Y-%m-%d %H:%M:%S')

In [6]: date_time
Out[6]: datetime.datetime(2015, 5, 1, 12, 0, 1)

**时间戳转string**

In [17]: time.strftime('%Y-%m-%d',time.localtime(aa))
Out[17]: '2015-06-05'

python 时间戳 datetime string 转换的更多相关文章

  1. Python time & datetime & string 相互转换

    #!/usr/bin/env python# -*- coding:utf-8 -*- # @Datetime : 2017/11/23 下午12:37# @Author : Alfred Xue# ...

  2. [Python]Bytes 和 String转换

    #----string to bytes------ # 方法一:直接复制bytes类型 b'<str>' b = b'Hello World' print(type(b)) print( ...

  3. python List和String 转换注意

    不能用str(list),t=['\x87\xe9\xa5\xb0\xef\xbc']In [28]: str(t)Out[28]: "['\\x87\\xe9\\xa5\\xb0\\xef ...

  4. python处理时间--- datetime模块

    1   Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块我在之前的文章已经有所介绍,它提供的接口与C标准库time.h基本一致.相比于tim ...

  5. python 使用time / datetime进行时间、时间戳、日期转换

    python 使用time 进行时间.时间戳.日期格式转换 #!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2017/11/7 15:53 # ...

  6. python 有关datetime时间日期 以及时间戳转换

    直接上代码 其中有注释 #coding=utf-8 import time import datetime def yes_time(): #获取当前时间 now_time = datetime.da ...

  7. C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

  8. Shell Python 日期和时间戳的互相转换

    一.初衷: 很多时候,时间的存储都是时间戳格式,如果需要展示就要转化成标准格式日期.也许会需要date和timestamp互转. 二.方法: 1.Shell下对date和timestamp的互转,是通 ...

  9. 分别用Excel和python进行日期格式转换成时间戳格式

    最近在处理一份驾驶行为方面的数据,其中要用到时间戳,因此就在此与大家一同分享学习一下. 1.什么是时间戳? 时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01 ...

随机推荐

  1. sizeof与strlen的区别 浅谈

    1.sizeof operator sizeof是C语言的一种单目操作符,如C语言的其他操作符++.- - 等,它并不是函数. Queries size of the object or type. ...

  2. 1076: [SCOI2008]奖励关( dp )

    期望状压dp.... ------------------------------------------------------------------ #include<cstdio> ...

  3. Python 第四篇:生成器、迭代器、装饰器、递归函数与正则表达式

    一:生成器:Generator,可以理解为是一种一个函数产生一个迭代器,而迭代器里面的数据是可以通过for循环获取的,那么这个函数就是一个生成器,即生成器是有函数生成的,创建生成器使用()表示,比如g ...

  4. 基于visual Studio2013解决C语言竞赛题之0710排序函数

     题目

  5. Boost学习之可移植路径操作--filesystem

    Boost.Filesystem 库为对路径.文件和目录进行查询和操作提供了可移植的工具,已经被C++标准委员会接纳包含到TR2中. 编译 使用Boost.Filesystem 库之前要先编译它,请参 ...

  6. poj 3767 I Wanna Go Home

    题意:n个点(从1-n编号) m条边 下面m行 u v dis 表示双向边u v的距离 n个点表示 每个点被势力1或2占据 这里保证1 城市由势力1占据,2城市由势力2占据 思路: 求2遍spfa() ...

  7. 6.6.2 自己主动泛型化(automatic generalization)

    6.6.2 自己主动泛型化(automatic generalization) 在这一章,我们已经实现了几个 F# 的高阶函数.也看到了在 F# 和 C# 中并排的实现.F# 实现的非常重要方面,是我 ...

  8. AsyncTask的用法总结

    这几天被AsyncTask虐得不行,在此总结下 首先: AsyncTask的参数介绍 在开发Android移动客户端的时候往往要使用多线程来进行操作,我们通常会将耗时的操作放在单独的线程执行,避免其占 ...

  9. CodeFirst 表之间的关联

    多重性关系可以是Optional(一个属性可拥有一个单个实例或没有) Required(一个属性必须拥有一个单个实例) Many很多的(一个属性可以拥有一个集合或一个单个实例). Has方法包括如下几 ...

  10. VPN指定某个程序,其实是改路由表(赛风支持VPN和SSH和SSH+模式)

    其实就是使用IE代理的意思,方法有很多.最简单的就是读取注册表中的代理信息.具体找;\Software\Microsoft\Windows\CurrentVersion\Internet Settin ...