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. a标签包input引起的问题

    最近公司中的一个项目中,有一个同事跟我说,他写的输入框不能选中输入内容了,并且光标也不能插入到已写好的文字其他位置. 简化了一下他的代码结构,如下: <a href="javascri ...

  2. Eclipse 打开编辑文件所在文件夹方法

    一个便捷的方法在eclipse的菜单中,依次点击Run->External Tools-> External Tools configurations添加一个新的工具 OpenContai ...

  3. java-No exception of type ConfigurationException can be thrown; an exception type must be a subclass of Throwable

    功能:读配置文件 java菜鸟:导入工程在报名处就开始报错,第一次遇到 import org.apache.commons.lang3.StringUtils; import org.apache.c ...

  4. linux 安装SVN

    1.环境centos6.4 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve -d -r /www/sv ...

  5. android去掉EditView的默认焦点问题

    在EditText的父级控件中找一个,设置成 <LinearLayout android:layout_width="0dp" android:layout_height=& ...

  6. MSSQL 查询分组前N条记录

    sql语句中,查询分组中前n条记录的sql语句如下 第一种方法 select * from consultingfeebill awhere n>(select count(*) from co ...

  7. selenium + python 多浏览器测试

    selenium + python 多浏览器测试 支持库包 在学习 Python + Selenium 正篇之前,先来看下对多浏览器模拟的支持.目前selenium包中已包含webdriver,hel ...

  8. mysql问题Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)的解决方法

    在mysql命令行界面输入 mysql> set old_passwords=0;mysql> SET PASSWORD FOR hhds_test=PASSWORD('hhds_test ...

  9. 用python3破解wingIDE

    值得注意的是,python2的整除/在python3中变成了//,sha方法细化成了sha1和sha256,所以破解文件需要更改加密方式和整除部分的编码方式,经过修改后,这个文件可以完美演算出破解码, ...

  10. IoC(控制反转)

    在传统的编程中,我们通过内部代码来控制组件之间的关系,但是这种实现方式,容易造成组件之间的高耦合.IoC能够很好地解决这个问题,它将组件间的关系从程序内部上提到外部容器来管理.IoC的核心目标是通过简 ...