使用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. 图解LinkedHashMap原理

    1 前言 LinkedHashMap继承于HashMap,如果对HashMap原理还不清楚的同学,请先看上一篇:图解HashMap原理 2 LinkedHashMap使用与实现 先来一张LinkedH ...

  2. maven 发现有一个包 需要升级包版本

    maven有个包需要升级版本号,但是升级完了之后,怎么编译都是原来的: 后来修改了一下版本号,然后编译,就好了,再把版本号改回来就行了: 本地版本库地址:File==>Other Setting ...

  3. java 异步操作

    /** * 异步删除 * * @param keys */ public void asycExecute(String keys) { ExecutorService executor = Exec ...

  4. 【mybatis源码学习】mybatis的参数处理

    一.mybatis的参数处理以及参数取值 1.单个参数 mybatis不做任何处理 取值方式: ​ #{参数名/任意名} <!-- Employee getEmpById(Integer id) ...

  5. Springboot属性加载与覆盖优先级与SpringCloud Config Service配置

    参考官方文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config. ...

  6. 离线安装pycharm数据库驱动

    这个数据库驱动,不是python的链接包 而是打开pycharm pro版后的数据库浏览器驱动. 也就是专业版比社区版方便的一个地方,可以直接边写代码,边看数据库结构,还可以拖动一些变量. 在线安装挺 ...

  7. SRC漏洞挖掘

    SRC目标搜集 文章类的平台 https://www.anquanke.com/src 百度搜索 首先得知道SRC厂商的关键字,利用脚本搜集一波. 比如[应急响应中心]就可以作为一个关键字.通过搜索引 ...

  8. springboot获取上下文ApplicationContext

    在springboot主程序里改成 public static void main(String[] args) { // SpringApplication.run(SpringbootAPP.cl ...

  9. SpringBoot常用注解(二)

    这是整个 web 工程的入口,也是与其他框架最大的不同之处.这里主要关注 @SpringBootApplication注解,它包括三个注解: @Configuration:表示将该类作用springb ...

  10. GAN代码实战

    batch normalization 1.BN算法,一般用在全连接或卷积神经网络中.可以增强整个神经网络的识别准确率以及增强模型训练过程中的收敛能力2.对于两套权重参数,例如(w1:0.01,w2: ...