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将时间戳装换成日期格式的更多相关文章

  1. js时间戳怎么转成日期格式

    原文地址:http://www.sufeinet.com/thread-1500-1-1.html js时间戳怎么转成日期格式这个在主群里有朋友§☆釺哖蟲...o问js时间戳怎么转成日期格式 ,他的问 ...

  2. js angular 时间戳转换成日期格式 年月日 yyyy-MM-dd

    昨天写项目,要把时间戳转换成日期格式发给后端 我就去网上找 看到的一些都不是我想要的 索性自己就写了一个如图 下面是angular 模式 $scope.getMyDate = function(str ...

  3. js时间戳转成日期格式

    将时间戳转换成日期格式:// 简单的一句代码var date = new Date(时间戳); //获取一个时间对象 注意:如果是uinx时间戳记得乘于1000.比如php函数time()获得的时间戳 ...

  4. web 前端 常见操作 将时间戳转成日期格式 字符串截取 使用mui制作选项卡

    1.将时间戳转成日期格式: //第一种 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString( ...

  5. python txt装换成excel

    工作中,我们需要经常吧一些导出的数据文件,例如sql查出来的结果装换成excel,用文件发送.这次为大家带上python装换excel的脚本 记得先安装wlwt模块,适用版本,python2-3 #c ...

  6. 将序列化成json格式的日期(毫秒数)转成日期格式

    <script> $(function () { loadInfo(); }) function loadInfo() { $.post("InfoList.ashx" ...

  7. CTime,Systemtime的比较还有转换成日期格式。

    vc为我们提供了两种日期型的变量. 一种是CTime.他的缺点就是年份只支持到2038年,以后的日期就不支持啦,如果你的项目有20-30年的寿命,你就选择使用SYSTEMTIME.这个时间函数来进行比 ...

  8. time_t转化成日期格式小工具

    time_t转化成日期格式小工具下载  http://files.cnblogs.com/files/lansan0701/TimeTool.zip

  9. 将序列化成json格式后日期(毫秒数)转成日期格式

    System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaS ...

随机推荐

  1. bzoj1003物流运输——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1003 DP好题: 直接找一个时间段的最短路,并用它来预处理出每个时间段的最小花费: f[i] ...

  2. margin---bug

    常见的浏览器下margin出现的bug IE6中双边距Bug:发生场合:当给父元素内第一个浮动元素设置margin-left(元素float:left)或margin-right(元素float:ri ...

  3. java web url编码解码问题(下载中文名文件)

    问题描述:需要url直接访问中文名的文件,类似于在地址栏里直接输入http://localhost:8080/example/丽江旅游攻略.doc 来进行文件下载,tomcat的server.xml文 ...

  4. 任务26:dotnet watch run 和attach到进程调试

    任务26:dotnet watch run 和attach到进程调试 dotnet watch run 的一种调试方法 打开VSCode,先关闭当前的文件夹 Ctrl+~快捷键 打开窗体. ls应该是 ...

  5. 黑马传智JavaEE57期 2019最新基础+就业+在职加薪_汇总

    黑马传智JavaEE57期 2019最新基础+就业+在职加薪 阶段1 语言基础+高级· 1-1-Java基础语法 第14节 数组 111

  6. CocoaPods(第三方类库管理工具)

    iOS安装CocoaPods详细过程  一.简介 什么是CocoaPods CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为“Pods” ...

  7. P5072 [Ynoi2015]盼君勿忘

    传送门 一开始理解错题意了--还以为是两个子序列相同的话只算一次--结果是子序列里相同的元素只算一次-- 对于一个区间\([l,r]\),设其中\(x\)出现了\(k\)次,那么它的贡献就是它的权值乘 ...

  8. LuoguP2055 [ZJOI2009]假期的宿舍【二分图最大匹配】By cellur925

    题目传送门 这道题开始感觉不出是二分图最大匹配的qwq.但是今天学了匈牙利算法,想来做几个题qwq.做这个题的时候想了很久它哪里是二分图,脑子里是“两列,每列有很多点的那种图 qwq.” 然后看了题解 ...

  9. python 处理时间和日期

    转自: https://www.cnblogs.com/65702708/archive/2011/04/17/2018936.html Python格式化日期时间的函数为datetime.datet ...

  10. C++构造函数与析构函数的解析

    创建一个对象时,常常需要作某些初始化的工作,例如对数据成员赋初值. 注意,类的数据成员是不能在声明类时初始化的.如果一个类中所有的成员都是公用的,则可以在定义对象时对数据成员进行初始化.如: clas ...