把时间戳转换为 datatime 格式
使用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 格式的更多相关文章
- jsp页面时间戳转换为时间格式
jstl中格式化时间戳 在jsp页面中使用jstl标签将long型的时间戳转换为格式化后的时间字符串 1.通过<jsp:useBean /> 导入java.util.Date类2.通过 ...
- el标签将时间戳转换为特定格式以及将数值保留特定小数
jsp中/el表达式中将后台传来的时间戳格式化为年月日时分秒 1.引入相关标签库 <%@taglib prefix="c" uri="http://java.sun ...
- 【Python爬虫实战--2】时间戳转换为指定格式日期
摘自:http://www.2cto.com/kf/201406/311477.html (1)方法: 方法一: 利用localtime()转换为时间数组,然后格式化为需要的格式,如 timeStam ...
- JavaScript前端将时间戳转换为日期格式
function (data) { var date = new Date(data) var Y = date.getFullYear() + '-' var M = (date.getMonth( ...
- C# 时间戳转换为时间格式
// 时间戳转为格式 public DateTime StampToDateTime(string timeStamp) { DateTime dateTimeStart = TimeZone.Cur ...
- 用C语言(apue)实现 把时间戳转换为国标格式的字符串(2017-07-17 22:36:12)的函数
/*******************************************************************************/ /** *** 函 数 名: cha ...
- excel中将时间戳转换为日期格式
将时间戳信息通常为s,将其转换的公式为: =TEXT((A1+8*3600)/86400+70*365+19,"yyyy-mm-dd hh:mm:ss")
- JS将时间戳转换为日期格式
function getDate(time){ var date =(new Date(parseInt(time))).toLocaleDateString() return date; } tim ...
- TP5在前端时间戳转换为时间格式
value="{:date('Y-m-d H:i:s',$data['add_date'])}" 例如: <td>{:date('Y-m-d H:i:s',$d[' ...
随机推荐
- EXCEL复制可见单元格
Excel筛选后,复制筛选后的单元格 1, 首先还是复制这一部分内容. 2, CTRL+G打开 "定位"窗口. 3, 在 "定位"窗口中选择"定位条件 ...
- 微信小程序之数据缓存
关于缓存,举个示例,假定我不是通过微信授权登录的方式,小程序又是如何识别我登录后的身份呢???效果图: 这个功能我是通过缓存实现的. 关键核心代码如下: wx.setStorage({ key: 'u ...
- shell case例子
-- --
- Xamarin图表开发基础教程(7)OxyPlot框架
Xamarin图表开发基础教程(7)OxyPlot框架 Xamarin.Forms中使用OxyPlot框架 在Xamarin. Forms平台上实现图表显示需要完成以下的步骤: 1.添加OxyPlot ...
- [转]JS - Promise使用详解2(ES6中的Promise)
原文地址:https://www.hangge.com/blog/cache/detail_1638.html 2015年6月, ES2015(即 ECMAScript 6.ES6) 正式发布.其中 ...
- Leetcode: Split BST
Given a Binary Search Tree (BST) with root node root, and a target value V, split the tree into two ...
- odoo开发笔记--ValueError Expected singleton
异常处理参考:https://stackoverflow.com/questions/31070640/valueerror-expected-singleton-odoo8 报错: ValueErr ...
- dotfuscator 在混淆.Net Framework 4.0以上版本的时候报错的解决方法
dotfuscator 在混淆.Net Framework 4.0以上版本的时候报错的解决方法 在混淆的时候报错了,错误描述大致如下: Could not find a compatible vers ...
- JVM 线上故障排查基本操作--内容问题排查
内存问题排查 说完了 CPU 的问题排查,再说说内存的排查,通常,内存的问题就是 GC 的问题,因为 Java 的内存由 GC 管理.有2种情况,一种是内存溢出了,一种是内存没有溢出,但 GC 不健康 ...
- [LeetCode] 803. Bricks Falling When Hit 打击砖块掉落
We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only i ...