-
jquery获取前一个月日期
一)
重构Date对象:
- Date.prototype.Format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1,
- "d+": this.getDate(),
- "H+": this.getHours(),
- "m+": this.getMinutes(),
- "s+": this.getSeconds(),
- "q+": Math.floor((this.getMonth() + 3) / 3),
- "S": this.getMilliseconds()
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
调用:
- var nowTime=new Date().Format("yyyy-MM-dd");
- console.log(nowTime);
二)
格式一:(yyyy-MM-dd HH:mm:SS)
- function getFormatDate(){
- var nowDate = new Date();
- var year = nowDate.getFullYear();
- var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
- var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
- var hour = nowDate.getHours()< 10 ? "0" + nowDate.getHours() : nowDate.getHours();
- var minute = nowDate.getMinutes()< 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
- var second = nowDate.getSeconds()< 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
- return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
- }
- var str = getFormatDate();
- console.log(str);
格式二:(yyyy-MM-dd)
- function getFormatDate(){
- var nowDate = new Date();
- var year = nowDate.getFullYear();
- var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
- var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
-
-
-
- return year + "-" + month + "-" + date;
- }
- var str = getFormatDate();
- console.log(str);
-
相关阅读:
Java设计模式—单例模式
Java集合框架
Java进程和线程
Java IO
Java异常类
Java面向对象—抽象类和接口
Java面向对象—多态
Java面向对象—继承
Java面向对象
Java基础语法
-
原文地址:https://www.cnblogs.com/telwanggs/p/9230740.html
Copyright © 2020-2023
润新知