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. C++的运算符

    C++的运算符十分丰富,使得C++的运算十分灵活方便.例如把赋值号(=)也作为运算符处理,这样,a=b=c=4就是合法的表达式,这是与其他语言不同的.C++提供了以下运算符: 算术运算符+(加)  - ...

  2. hibernate 配置文件 和一个 id生成类BaseEntity.java 和一个hibernate工具类 HibernatUtils.java

    package com; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate ...

  3. nginx 解决400 bad request 的方法

    nginx的400错误比较难查找原因,因为此错误并不是每次都会出现的,另外,出现错误的时候,通常在浏览器和日志里看不到任何有关提示. 经长时间观察和大量试验查明,此乃request header过大所 ...

  4. jQuery手写几个常见的滑动下拉菜单 分分秒秒学习JS

    一般的企业网站再我们再实际工作中,有些特效,用jQuery来做,显得极其简单,除非一些大的公司,需要封装自己的类. 今天,我们讲解jQuery入门知识,来写几个简单jQuery滑动下拉菜单.感受一下j ...

  5. Introduction to the Build Lifecycle

    Introduction to the Build Lifecycle Table Of Contents Build Lifecycle Basics Setting Up Your Project ...

  6. perl 回调必须是函数引用

    [root@wx03 lib]# cat a1.pl use AE; use AnyEvent; ##定义watch my $t = AnyEvent->timer( after => 0 ...

  7. POJ 3090 Visible Lattice Points 欧拉函数

    链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...

  8. ZOJ 3829 Known Notation 乱搞

    乱搞: 1.数字的个数要比*的个数多一个,假设数字不足须要先把数字补满 2.最优的结构应该是数字都在左边,*都在右边 3.从左往右扫一遍,遇到数字+1,遇到*-1,假设当前值<1则把这个*和最后 ...

  9. JavaScript提高:005:ASP.NET使用easyUI TABS标签显示问题

    前面使用easy ui来实现了一个tabs标签(http://blog.csdn.net/yysyangyangyangshan/article/details/38307477),只是在ASP.NE ...

  10. Denny Zhang:一辈子做一个自由职业者

    程序猿訪谈录供稿 Denny是一个旅居美国的自由职业者,这是一份让人羡慕的职业,选择这个职业意味着他已经实现某种程度上的经济自由,能够最大限度的做自己喜欢的事情,对他来说,选择自由职业作为自己终生的事 ...