媛技术贴

  • 首页
  • 微信小程序
  • 数据库
  • VueJs
  • 算法
  • 兼容性
  • 面试
  • React.js

中国标准时间Mon, 24 Jul 2017 15:31:05 +0800格式化转换 js

发表于 2020-09-07 | 分类于 VueJs
贴上的标签: js 阅读时长 ≈ 7 分钟

中国标准时间Mon, 24 Jul 2017 15:31:05 +0800格式化转换 js


function format (time, format){

	alert(time)

	var t = new Date(time);

	var tf = function(i){return (i < 10 ? '0' : '') + i};

	return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){

		switch(a){

		  case 'yyyy':

			return tf(t.getFullYear());

			break;

		  case 'MM':

			return tf(t.getMonth() + 1);

			break;

		  case 'mm':

			return tf(t.getMinutes());

			break;

		  case 'dd':

			return tf(t.getDate());

			break;

		  case 'HH':

			return tf(t.getHours());

			break;

		  case 'ss':

			return tf(t.getSeconds());

			break;

		}

	})
}

alert(format('Mon, 24 Jul 2017 15:31:05 +0800', 'yyyy-MM-dd HH:mm:ss'))



上一篇:如何让网站首页变灰色
下一篇:没有了
jing

Jing

座右铭:只有非常努力才会觉得毫不费力

92 总文章数
44 总标签
44 浏览人数
关于作者:前端代码搬运工
致力成为一个技术女肥宅
QQ:714195347
邮箱:714195347@qq.com
学前端找博主有海量资源等着你!!!
相关链接
  • Laravel China社区
  • GitHub
  • 橡皮擦擦
  • 资源作品集
  • 个人博客
© 2017 aicode.site by HUANGJING 阿里云计算有限公司
本站运行时长: 1948