js时间转换相关
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时间转换相关的更多相关文章
- JS 时间转换函数 字符串时间转换毫秒(互转)
字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : t ...
- python 时间转换相关
最近需要操作时间的地方相当的多,包括打点,包括时间转换. 罗列最近遇到的两个需求. 1. 关于上篇文章写的base64上传图片的问题,我使用了打点来计算解码需要多少时间.这个对时间精度要求是比较高的. ...
- JS时间转换的一个坑位
在做项目的时候,无意发现了一个小东西. new Date('2018-05-15') new Date('2018-5-15') 输出的结果是不同的,相差了8小时.然后让我回忆到之前看的一个时间转换函 ...
- js 时间转换
//时间转换成时间戳 function DateToUnix(string) { var f = string.split(' ', 2); var d = (f[0] ? f[0] : '').sp ...
- JS时间转换,url编码,jquery返回类型等问题
1.当时间被转换为json格式后会被转换成 /Date(...)/ 这种格式,其中...为时间转换成妙后的一串整数 function changeDateFormat(cellval) { )); v ...
- js时间转换
1. 将时间戳转换成日期格式 // 简单的一句代码 var date = new Date(时间戳); //获取一个时间对象 /** 1. 下面是获取时间日期的方法,需要什么样的格式自己拼接起来就好了 ...
- js时间转换,能够把时间转换成yyyymmdd格式或yyyymm格式
//type为1则转换成yyyymmdd格式,type为2则转换成yyyymm格式 function formatTime(time,type){ var temp_time=new Number(t ...
- js 时间转换毫秒的四种方法(转)
将时间转换为毫秒数的方法有四个: Date.parse()Date.UTCvalueOf()getTime() 1. Date.parse():该方法接受一个表示日期的字符串参数,然后尝试根据这个日期 ...
- PostgreSQL 时间转换
背景:最近频繁使用到时间转换相关的操作,特此小记. 1.实时取最近24小时内数据. select now() - interval '24h'; 通过sql获得符合要求的时间段,当做where条件即可 ...
随机推荐
- 集合框架null与size=0
被QA人员一眼指出来的问题,唉,好丢人 上栗子
- oracle之检查点(Checkpoint)
检查点是一个数据库事件,它把修改数据从高速缓存写入磁盘,并更新控制文件和数据文件.检查点分为三类:1)局部检查点:单个实例执行数据库所有数据文件的一个检查点操作,属于此实例的全部脏缓存区写入数据文件. ...
- c# 读取其他程序的ListView内容
ArcMap没找到一个导出图层字段结构的功能,自已花点时间用C#做了个小工具,专门用来导arcmap中图层属性面板中的字段信息. 使用说明: 1) 点击“查找窗口”按钮.2) 在ListView控件上 ...
- Java文件下载的几种方式
public HttpServletResponse download(String path, HttpServletResponse response) { try { // path是指欲下载的 ...
- [偏微分方程教程习题参考解答]4.1Duhamel 原理
1. 如果已知下述常微分方程的特定初值问题 $$\bex \sedd{\ba{ll} -y''+y=0,&x>0,\\ y(0)=0,\quad y'(0)=1 \ea} \eex$$ ...
- 解决Asp.net Mvc返回JsonResult中DateTime类型数据格式的问题
问题背景: 在使用asp.net mvc 结合jquery esayui做一个系统,但是在使用使用this.json方法直接返回一个json对象,在列表中显示时发现datetime类型的数据在转为字符 ...
- <转>如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
原文链接:http://www.vaikan.com/use-multiple-cpu-cores-with-your-linux-commands/ 你是否曾经有过要计算一个非常大的数据(几百GB) ...
- Name-based virtual servers 给予名称的虚拟服务
nginx first decides which server should process the request. Let’s start with a simple configuration ...
- LRU Cache的实现
代码如下: 来自为知笔记(Wiz)
- web.xml 配置介绍
这个不是原创,有点早了,具体从哪里来的已经记不得了.但是东西是实实在在的. 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<c ...