1.json时间格式转换

function ChangeDateFormat(jsondate) {
if (!jsondate||jsondate.length < 1) {return ""; }
jsondate = jsondate.replace("/Date(", "").replace(")/", "");
if (jsondate.indexOf("+") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("+"));
}
else if (jsondate.indexOf("-") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("-"));
} var date = new Date(parseInt(jsondate, 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
} //带日期
function ChangeDateTimeFormat(jsondate) {
if (!jsondate || jsondate.length < 1) { return ""; }
jsondate = jsondate.replace("/Date(", "").replace(")/", "");
if (jsondate.indexOf("+") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("+"));
}
else if (jsondate.indexOf("-") > 0) {
jsondate = jsondate.substring(0, jsondate.indexOf("-"));
} var date = new Date(parseInt(jsondate));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}

2.js中两个时间的差

function DateS(a,b,c) {
var arr = ChangeDateFormat(a).split("-");
var starttime = new Date(arr[0], arr[1] - 1, arr[2]);
var starttimes = starttime.getTime(); var arr = ChangeDateFormat(b).split("-");
var lktimes = new Date(arr[0], arr[1] - 1, arr[2]);
var lktimes = starttime.getTime();
var ltime = 0;
if (c === 'y' || c === 'Y') {
ltime = (starttimes - lktimes) / (86400000*365);
} if (c === 'm' || c === 'M') {
ltime = (starttimes - lktimes) / (86400000 * 365/12);
}
if (c === 'd' || c === 'D') {
ltime = (starttimes - lktimes) / 86400000;
}
if (c === 'h' || c === 'H') {
ltime = (starttimes - lktimes) / 3600000;
}
if (c === 'MM' || c === 'mm') {
ltime = (starttimes - lktimes) / 60000;
}
if (c === 'ss' || c === 'SS') {
ltime = (starttimes - lktimes) / 1000;
}
return ltime;
}
//输入的值与当前时间差
function DateSNow(a, c) {
var arr = ChangeDateFormat(a).split("-");
var starttime = new Date(arr[0], arr[1] - 1, arr[2]); var starttimes = starttime.getTime(); var myDate = new Date(); var mmDate = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate()); var lktimes = mmDate.getTime();
var ltime = 0;
if (c === 'y' || c === 'Y') {
ltime = (starttimes - lktimes) / (86400000 * 365);
} if (c === 'm' || c === 'M') {
ltime = (starttimes - lktimes) / (86400000 * 365 / 12);
}
if (c === 'd' || c === 'D') {
ltime = (starttimes - lktimes) / 86400000;
}
if (c === 'h' || c === 'H') {
ltime = (starttimes - lktimes) / 3600000;
}
if (c === 'MM' || c === 'mm') {
ltime = (starttimes - lktimes) / 60000;
}
if (c === 'ss' || c === 'SS') {
ltime = (starttimes - lktimes) / 1000;
}
return ltime;
}

js时间转换相关的更多相关文章

  1. JS 时间转换函数 字符串时间转换毫秒(互转)

    字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : t ...

  2. python 时间转换相关

    最近需要操作时间的地方相当的多,包括打点,包括时间转换. 罗列最近遇到的两个需求. 1. 关于上篇文章写的base64上传图片的问题,我使用了打点来计算解码需要多少时间.这个对时间精度要求是比较高的. ...

  3. JS时间转换的一个坑位

    在做项目的时候,无意发现了一个小东西. new Date('2018-05-15') new Date('2018-5-15') 输出的结果是不同的,相差了8小时.然后让我回忆到之前看的一个时间转换函 ...

  4. js 时间转换

    //时间转换成时间戳 function DateToUnix(string) { var f = string.split(' ', 2); var d = (f[0] ? f[0] : '').sp ...

  5. JS时间转换,url编码,jquery返回类型等问题

    1.当时间被转换为json格式后会被转换成 /Date(...)/ 这种格式,其中...为时间转换成妙后的一串整数 function changeDateFormat(cellval) { )); v ...

  6. js时间转换

    1. 将时间戳转换成日期格式 // 简单的一句代码 var date = new Date(时间戳); //获取一个时间对象 /** 1. 下面是获取时间日期的方法,需要什么样的格式自己拼接起来就好了 ...

  7. js时间转换,能够把时间转换成yyyymmdd格式或yyyymm格式

    //type为1则转换成yyyymmdd格式,type为2则转换成yyyymm格式 function formatTime(time,type){ var temp_time=new Number(t ...

  8. js 时间转换毫秒的四种方法(转)

    将时间转换为毫秒数的方法有四个: Date.parse()Date.UTCvalueOf()getTime() 1. Date.parse():该方法接受一个表示日期的字符串参数,然后尝试根据这个日期 ...

  9. PostgreSQL 时间转换

    背景:最近频繁使用到时间转换相关的操作,特此小记. 1.实时取最近24小时内数据. select now() - interval '24h'; 通过sql获得符合要求的时间段,当做where条件即可 ...

随机推荐

  1. 【转】Mac 10.10 yosemite 安装samba替代系统samba组件 -- samba不错不错

    原文网址:http://gcell.blog.163.com/blog/static/52666594201501084530277/ 1.首先,在系统偏好设置的共享设置中,关掉局域网文件共享(去掉打 ...

  2. 更改 input type 的值

    需要实现的效果:一个输入框,当输入框未获得焦点的时候,value 值为 “密码”:当输入框失去焦点的时候,输入内容显示为”*****” <input name=”password” type=” ...

  3. 纠结的ARC

    xcode不断进步,在xcode4中引入了ARC的概念.您用或者不用它就在那里,于是有了本文:如何在未使用arc的工程中引入一个使用了arc特性的文件,如何在arc工程中引用未使用arc的文件.其实说 ...

  4. C# 使用NPlot绘图

    首先要将下载的NPlot.dll加到工具箱里,拖一个控件到窗体上,声明using NPlot. 一.入门 1. 对所绘的图进行打印与保存 private void print() { myPlot.P ...

  5. DataReader方式 获取数据的操作

    一.使用DataReader读取为对象List /// <summary> /// 获得数据列表List<>,DataReader 使用参数的 /// </summary ...

  6. free-jqGrid

    PM> Install-Package free-jqGrid jqGrid 是一个用来显示网格数据的jQuery插件,通过使用jqGrid可以轻松实现前端页面与后台数据的ajax异步通信.文档 ...

  7. win7 下配置resin的一些tip

    一.如何查看jdk安装目录: 通过不同方法搜索javac看看, javac.exe 是java的编译器: 可用的搜索方法: 1.cmd 控制台:  where javac 2.开始菜单的搜索: 一直到 ...

  8. opengl奔溃问题

    按照网上的教程编译成功,当时运行时老是奔溃(不弹出任何提示,窗口变灰色).遂更新了ATI的显卡驱动果然可以运行了,哈哈 http://support.amd.com/en-us/download/de ...

  9. LeetCode Database: Delete Duplicate Emails

    Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique ...

  10. java中子类与基类变量间的赋值

    Java中子类与基类变量间的赋值 子类对象可以直接赋给基类变量. 基类对象要赋给子类对象变量,必须执行类型转换, 其语法是: 子类对象变量=(子类名)基类对象名; 也不能乱转换.如果类型转换失败Jav ...