JS日期格式化,拿到时间段日期
来源:互联网 发布:怎么在淘宝上注册店 编辑:程序博客网 时间:2024/05/29 03:47
//日期操作(yyyy-mm-dd,30,+/-)
function dateOperator(date,days,operator){
date = date.replace(/-/g,"/");var nd = new Date(date);
nd = nd.valueOf();
if(operator=="+"){
nd = nd + days * 24 * 60 * 60 * 1000;
}else if(operator=="-"){
nd = nd - days * 24 * 60 * 60 * 1000;
}else{
return false;
}
nd = new Date(nd);
var y = nd.getFullYear();
var m = nd.getMonth()+1;
var d = nd.getDate();
if(m <= 9) m = "0"+m;
if(d <= 9) d = "0"+d;
var temdate = y+"-"+m+"-"+d;
return temdate ;
}
//日期格式化
function dateToString(sdate){
if(sdate instanceof Date){
var dd = sdate.getDate() < 10 ? "0" + sdate.getDate() : sdate.getDate().toString();
var mmm = (sdate.getMonth()+1) < 10? "0"+(sdate.getMonth()+1) : (sdate.getMonth()+1);
var yyyy = sdate.getFullYear().toString();
return yyyy+'-'+mmm+'-'+dd;
}else{
return sdate;
}
}
当前时间:var endDate = dateToString(new Date());
阅读全文
0 0
- JS日期格式化,拿到时间段日期
- js日期转换--日期格式化
- 日期时间段
- javascript 日期格式化 js日期格式化
- JS解析,格式化日期
- js日期格式化
- js日期格式化
- js时间日期格式化
- js日期格式化
- js格式化日期
- js日期格式化函数
- js日期格式化
- js 格式化日期
- JS格式化日期
- js格式化日期
- js 格式化日期
- js日期格式化函数
- JS日期格式化
- 关于join函数和split函数
- 项目中遇到的问题
- Python安装rar解压包(for Arcgis篇)
- ArcGIS Engine进行编辑时,提示错误:Objects in this class cannot be updated outside an edit session [line_2]
- eclipse中合并svn代码 -- 将分支branch上的代码合并到主干trunk上
- JS日期格式化,拿到时间段日期
- xml基础知识(1)
- [Leetcode] 283. Move Zeroes 解题报告
- c\c++ 输入输出
- Hadoop的分布式架构改进与应用
- xmpp的XmppConnection类
- C++ 标准函数库 —— 文件的输入输出 (Input/Output with files)
- 垂直居中各种条件小的适用情况
- hdu 1397 Goldbach's Conjecture