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. 使用VirtualBox SDK之初步编译

    VirtualBox成功编译出来后,在生成的out文件夹中会发现有SDK文件夹(当然也可以直接从官网下SDK),里面有例子,但是直接用Visual Studio编译的话会出一大堆错误,本文就是讲解如何 ...

  2. Eclipse用法和技巧十八:减少不必要的输入

    写代码的时候,很多人都有一个原则,尽量上输入.依靠IDE自动生成的代码,一般可读性,排版什么的都还是不错的,最主要的一般不会有什么低级错误.今天介绍几个在eclipse环境中,常用的依靠eclipse ...

  3. Pro Android 4 第五章 理解Intent

         Android引入了一个名为Intent的概念用来唤醒各种组件.Android中的组件包括:activities(UI 组件),services(后台代码),broadcast receiv ...

  4. Embedded Linux Primer----嵌入式Linux基础教程--章节介绍

    章节介绍 第一章,“导引”,简要介绍了Linux被迅速应用在嵌入式环境的驱动因素,介绍了与嵌入式Linux相关的几个重要的标准和组织. 第二章,“第一个嵌入式经历”,介绍了与后几章所构建的嵌入式Lin ...

  5. 在webform中调用JS的技巧

    一,执行删除操作,点击按钮时弹出对话框询问是否确认删除,点击确定,删除并在删除完成后弹出删除成功:点击取消不删除 1.在aspx源 代码中加入JavaScript代码 <script langu ...

  6. Html input 限制输入中英文字符,及字符数量统计

    margin:20px 0px 0px; font-family:Arial; color:rgb(51,51,51)"> 验证用户名的一个例子: html: <input ty ...

  7. MFC用GDI+动感歌词的制作

    源代码:http://download.csdn.net/detail/nuptboyzhb/4219669 源代码: 1.       插入一个对话框的资源,删除默认控件,并为对话框创建一个类,命名 ...

  8. 486E - LIS of Sequence(LIS)

    题意:给一个长度为n的序列.问每一个数关于序列的LIS(longest increasing subsequence)是什么角色. 这里分了三种: 1.此数没有出如今随意一条LIS中 2.此数出如今至 ...

  9. Eclipse Workspace Unavailable

    开启Eclipse 提示: Workspace Unavailable: Workspace in use or cannot be created, choose a different one. ...

  10. Windows 8 动手实验系列教程 实验6:设置和首选项

    动手实验 实验6:设置和首选项 2012年9月 简介 实验3介绍了合约并演示了应用程序如何轻松地与共享和搜索合约实现集成.合约同样包含设置超级按钮,它对活动的Windows应用商店应用的设置进行修改. ...