js将时间戳装换成日期格式
13位时间戳改为yyyy-MM-dd HH-mm-ss 格式
目标时间戳:1516324500000
- formatDateTime (unix) { // 转换时间戳
- var date = new Date(unix)// 时间戳为10位需*1000,时间戳为13位的话不需乘1000
- var Y = date.getFullYear() + '-'
- var M = (date.getMonth() + < ? '' + (date.getMonth() + ) : date.getMonth() + ) + '-'
- var D = date.getDate() + ' '
- var h = date.getHours() + ':'
- var m = date.getMinutes() + ':'
- var s = date.getSeconds()
- return Y + M + D + h + m + s
- }
- //将时间戳改为yyyy-MM-dd HH-mm-ss
- function formatDateTime(unix) {
- var now = new Date(parseInt(unix) * 1);
- now = now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
- if(now.indexOf("下午") > 0) {
- if (now.length == 18) {
- var temp1 = now.substring(0, now.indexOf("下午")); //2014/7/6
- var temp2 = now.substring(now.indexOf("下午") + 2, now.length); // 5:17:43
- var temp3 = temp2.substring(0, 1); // 5
- var temp4 = parseInt(temp3); // 5
- temp4 = 12 + temp4; // 17
- var temp5 = temp4 + temp2.substring(1, temp2.length); // 17:17:43
- now = temp1 + temp5; // 2014/7/6 17:17:43
- now = now.replace("/", "-"); // 2014-7/6 17:17:43
- now = now.replace("/", "-"); // 2014-7-6 17:17:43
- }else {
- var temp1 = now.substring(0, now.indexOf("下午")); //2014/7/6
- var temp2 = now.substring(now.indexOf("下午") + 2, now.length); // 5:17:43
- var temp3 = temp2.substring(0, 2); // 5
- if (temp3 == 12){
- temp3 -= 12;
- }
- var temp4 = parseInt(temp3); // 5
- temp4 = 12 + temp4; // 17
- var temp5 = temp4 + temp2.substring(2, temp2.length); // 17:17:43
- now = temp1 + temp5; // 2014/7/6 17:17:43
- now = now.replace("/", "-"); // 2014-7/6 17:17:43
- now = now.replace("/", "-"); // 2014-7-6 17:17:43
- }
- }else {
- var temp1 = now.substring(0,now.indexOf("上午")); //2014/7/6
- var temp2 = now.substring(now.indexOf("上午")+2,now.length); // 5:17:43
- var temp3 = temp2.substring(0,1); // 5
- var index = 1;
- var temp4 = parseInt(temp3); // 5
- if(temp4 == 0 ) { // 00
- temp4 = "0"+temp4;
- }else if(temp4 == 1) { // 10 11 12
- index = 2;
- var tempIndex = temp2.substring(1,2);
- if(tempIndex != ":") {
- temp4 = temp4 + "" + tempIndex;
- }else { // 01
- temp4 = "0"+temp4;
- }
- }else { // 02 03 ... 09
- temp4 = "0"+temp4;
- }
- var temp5 = temp4 + temp2.substring(index,temp2.length); // 07:17:43
- now = temp1 + temp5; // 2014/7/6 07:17:43
- now = now.replace("/","-"); // 2014-7/6 07:17:43
- now = now.replace("/","-"); // 2014-7-6 07:17:43
- }
- return now;
- };
- alert(formatDateTime(1516324500000));
js将时间戳装换成日期格式的更多相关文章
- js时间戳怎么转成日期格式
原文地址:http://www.sufeinet.com/thread-1500-1-1.html js时间戳怎么转成日期格式这个在主群里有朋友§☆釺哖蟲...o问js时间戳怎么转成日期格式 ,他的问 ...
- js angular 时间戳转换成日期格式 年月日 yyyy-MM-dd
昨天写项目,要把时间戳转换成日期格式发给后端 我就去网上找 看到的一些都不是我想要的 索性自己就写了一个如图 下面是angular 模式 $scope.getMyDate = function(str ...
- js时间戳转成日期格式
将时间戳转换成日期格式:// 简单的一句代码var date = new Date(时间戳); //获取一个时间对象 注意:如果是uinx时间戳记得乘于1000.比如php函数time()获得的时间戳 ...
- web 前端 常见操作 将时间戳转成日期格式 字符串截取 使用mui制作选项卡
1.将时间戳转成日期格式: //第一种 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString( ...
- python txt装换成excel
工作中,我们需要经常吧一些导出的数据文件,例如sql查出来的结果装换成excel,用文件发送.这次为大家带上python装换excel的脚本 记得先安装wlwt模块,适用版本,python2-3 #c ...
- 将序列化成json格式的日期(毫秒数)转成日期格式
<script> $(function () { loadInfo(); }) function loadInfo() { $.post("InfoList.ashx" ...
- CTime,Systemtime的比较还有转换成日期格式。
vc为我们提供了两种日期型的变量. 一种是CTime.他的缺点就是年份只支持到2038年,以后的日期就不支持啦,如果你的项目有20-30年的寿命,你就选择使用SYSTEMTIME.这个时间函数来进行比 ...
- time_t转化成日期格式小工具
time_t转化成日期格式小工具下载 http://files.cnblogs.com/files/lansan0701/TimeTool.zip
- 将序列化成json格式后日期(毫秒数)转成日期格式
System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaS ...
随机推荐
- C#使用SendMessage发送组合键
有时需要出发菜单功能,例如发送ALT + F打开应用程序的文件菜单,如何使用SendMessage实现呢? 使用用spy++截取的ALT+F的消息内容(如何使用spy++,请熟悉的高手指点下,我使用s ...
- bzoj4516
后缀自动机 留个板子 upd:大概懂了 每次新加入的npRight集合肯定只有最后一个位置,那么求所有长得不一样的子串贡献就是Max-Min+1,因为Right集合只有这一个位置,所以这Max-Min ...
- 6-5 Haar特征2
在遍历的过程中还需要考虑到一个步长的问题.这个模板一次滑动10个像素,那么总共就需要滑动9次.再加上最开始的第0次,合计在水平方向上和竖直方向上分别都有10个这样的模板,总共也就是100个模板.要计算 ...
- VMware ESXI虚拟机挂载移动硬盘
Windows server2008 R2 1.“编辑虚拟机设置”,点击“添加” 2.点击添加“USB控制器”: 3.添加完“USB控制器”以后,再点击添加“USB设备”: 完成即可:如果系统里面不显 ...
- hdoj5115【区间DP·基础】
题意: 有n头wolf排成一排,杀一头wolf回受到受到的伤害=它的本身a[i]+相邻两个b[i-1]+b[i+1].然后杀死第k个位置的wolf的话,k-1和k+1默认相邻(满足的话). 思路: 用 ...
- python __builtins__ type类 (69)
69.'type', 返回对象类型 class type(object) | type(object_or_name, bases, dict) | type(object) -> the ob ...
- mysqldump 工具使用详解——参数选项
mysqldump 简介 mysqldump 是一种用于逻辑备份的客户端工具,它会产生一套能够重新构建数据库或表的SQL语句.所谓逻辑备份:是利用SQL语言从数据库中抽取数据并存于二进制文件的过程.逻 ...
- 左耳朵耗子:我对 GitLab 误删除数据库事件的几点思考
参考链接:https://www.infoq.cn/article/some-thoughts-on-gitlab-accidentally-deleting-database 太平洋时间 2017 ...
- 调试的时候禁止chrome缓存图片
https://blog.csdn.net/yiifaa/article/details/54290047 https://blog.csdn.net/xinghuo0007/article/deta ...
- 跟我一起玩Win32开发(2):完整的开发流程
上一篇中我给各位说了一般人认为C++中较为难的东西——指针.其实对于C++,难点当然不局限在指针这玩意儿上,还有一些有趣的概念,如模板类.虚基类.纯虚函数等,这些都是概念性的东西,几乎每一本C++书上 ...