使用time
timeStamp = 1381419600
timeArray = time.localtime(timeStamp)
otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
print otherStyleTime # 2013--10--10 23:40:00
# 使用datetime
timeStamp = 1381419600
dateArray = datetime.datetime.utcfromtimestamp(timeStamp)
otherStyleTime = dateArray.strftime("%Y--%m--%d %H:%M:%S")
print otherStyleTime # 2013--10--10 15:40:00

2.4 获取当前时间并且用指定格式显示

 1 # time获取当前时间戳
2 now = int(time.time()) # 1533952277
3 timeArray = time.localtime(now)
4 print timeArray
5 otherStyleTime = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
6 print otherStyleTime
7
8 # 结果如下
9 time.struct_time(tm_year=2018, tm_mon=8, tm_mday=11, tm_hour=9, tm_min=51, tm_sec=17, tm_wday=5, tm_yday=223, tm_isdst=0)
10 2018--08--11 09:51:17
11
12
13 # datetime获取当前时间,数组格式
14 now = datetime.datetime.now()
15 print now
16 otherStyleTime = now.strftime("%Y--%m--%d %H:%M:%S")
17 print otherStyleTime
18
19 # 结果如下:
20 2018-08-11 09:51:17.362986
21 2018--08--11 09:51:17

把时间戳转换为 datatime 格式的更多相关文章

  1. jsp页面时间戳转换为时间格式

    jstl中格式化时间戳   在jsp页面中使用jstl标签将long型的时间戳转换为格式化后的时间字符串 1.通过<jsp:useBean /> 导入java.util.Date类2.通过 ...

  2. el标签将时间戳转换为特定格式以及将数值保留特定小数

    jsp中/el表达式中将后台传来的时间戳格式化为年月日时分秒 1.引入相关标签库 <%@taglib prefix="c" uri="http://java.sun ...

  3. 【Python爬虫实战--2】时间戳转换为指定格式日期

    摘自:http://www.2cto.com/kf/201406/311477.html (1)方法: 方法一: 利用localtime()转换为时间数组,然后格式化为需要的格式,如 timeStam ...

  4. JavaScript前端将时间戳转换为日期格式

    function (data) { var date = new Date(data) var Y = date.getFullYear() + '-' var M = (date.getMonth( ...

  5. C# 时间戳转换为时间格式

    // 时间戳转为格式 public DateTime StampToDateTime(string timeStamp) { DateTime dateTimeStart = TimeZone.Cur ...

  6. 用C语言(apue)实现 把时间戳转换为国标格式的字符串(2017-07-17 22:36:12)的函数

    /*******************************************************************************/ /** *** 函 数 名: cha ...

  7. excel中将时间戳转换为日期格式

    将时间戳信息通常为s,将其转换的公式为: =TEXT((A1+8*3600)/86400+70*365+19,"yyyy-mm-dd hh:mm:ss")

  8. JS将时间戳转换为日期格式

    function getDate(time){ var date =(new Date(parseInt(time))).toLocaleDateString() return date; } tim ...

  9. TP5在前端时间戳转换为时间格式

     value="{:date('Y-m-d H:i:s',$data['add_date'])}"  例如: <td>{:date('Y-m-d H:i:s',$d[' ...

随机推荐

  1. 以SQL命令方式调用存储过程

    string str = "Data Source=.;Initial Catalog=***;Integrated Security=True"; using (SqlConne ...

  2. Oralce 如何将查询结果中的0转成空的

    我们遇到过大多的情况的需求是查询结果中空转为0,这个可以通过oracle的NVL()函数就可以搞定. 之前做报表客户有个需求,查询出结果为0 要转成空的,不显示0 那么在oracle有没有现成函数能搞 ...

  3. html页面自适应宽度

    html页面实现响应式的方式有很多,本篇介绍懒人必备一招见效的方法. 在head标签中加入 <meta name="viewport" content="width ...

  4. 【linux基础err】NVIDIA-SMI has failed because it could't communicate with the NVIDIA driver.

    问题 安装nvidia driver和cuda关机重启之后出现不能进入系统的问题,进入命令行模式使用nvidia-smi检查驱动的问题. nvidia-smi NVIDIA-SMI has faile ...

  5. [LeetCode] 243. Shortest Word Distance 最短单词距离

    Given a list of words and two words word1 and word2, return the shortest distance between these two ...

  6. [LeetCode] 583. Delete Operation for Two Strings 两个字符串的删除操作

    Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 t ...

  7. .NET(C#)有哪些主流的ORM框架,SqlSugar,Dapper,EF还是...

    前言 在以前的一篇文章中,为大家分享了<什么是ORM?为什么用ORM?浅析ORM的使用及利弊>.那么,在目前的.NET(C#)的世界里,有哪些主流的ORM,SqlSugar,Dapper, ...

  8. 【机器学习之二】python开发spark案例

    环境 spark-1.6 python3.5 一.wordcount # -*- coding:utf-8 -*- ''' Created on 2019年5月13日 @author: Adminis ...

  9. Nginx是什么及作用?代理和反向代理解析

    一:介绍 nginx是一个高性能的HTTP和反向代理服务器,其特点是占用内存少,并发能力强. 二:名词介绍 代理服务器: 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络 ...

  10. python面试题100道

    python 100道面试题 1.一行代码实现1--100之和 利用sum()函数求和 2.如何在一个函数内部修改全局变量 函数内部global声明 修改全局变量 3.列出5个python标准库 os ...