博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js 的date的format时间,获取当前时间,前一天的日期
阅读量:4571 次
发布时间:2019-06-08

本文共 1030 字,大约阅读时间需要 3 分钟。

Date.prototype.Format = function (fmt) { //author: meizz     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;}		function daysJian(){  	  var date = new Date('2006-7-1 8:9:4.18');//获取当前时间  	  date.setDate(date.getDate()-1);//设置天数 -1 天  	   var time = date.Format("yyyy-MM-dd");  	   return time;		}	console.log(daysJian());

console.log("=====================")

console.log(new Date(1234567897789).Format("yyyy-MM-dd hh:mm:ss"))

  

转载于:https://www.cnblogs.com/muamaker/p/7219942.html

你可能感兴趣的文章
UI基础篇之UIScrollView
查看>>
vc 网络编程(socket)
查看>>
tex中把参考文献标题删除
查看>>
Linux下NFS服务器的搭建与配置
查看>>
1501 二叉树最大宽度和高度
查看>>
MySQL索引选择问题(要相信MySQL自己选择索引的能力)
查看>>
Angular i18n
查看>>
SQL Server 2008 教程
查看>>
docker安装
查看>>
JAVA boolean 类型
查看>>
MYSQL进阶学习笔记七:MySQL触发器的创建,应用及管理!(视频序号:进阶_16,17)...
查看>>
hdu 4069 福州赛区网络赛I DLC ***
查看>>
java web 方面
查看>>
Spring 源码学习(2) —— FactoryBean 的使用
查看>>
wiki 3143 二叉树的前序、中序及后序遍历
查看>>
一位创业者创业失败后,成功的做了一个创业孵化器!
查看>>
程序猿打新总结 6月份 新股申购秘籍
查看>>
导出文本pdf文件
查看>>
C. Table Decorations(Codeforces Round 273)
查看>>
LayoutInflater和inflate()方法的使用方法
查看>>