图文详情
formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
// 时间格式化
formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
使用:
formatTime(new Date())
相关推荐
相关新闻
- 高德地图WEB版基础控件展示 2019-03-31
- 微信小程序里使用SVG矢量图标方法详解 2019-03-31
- Ajax引擎 ajax请求步骤详细代码 2019-03-31
- layUI ajax加载html页面后重新渲染的方法 2019-03-31
- 使用IDEA编写jsp时EL表达式不起作用的问题及解决方法 2019-03-31
- 浅析IE浏览器关于ajax的缓存机制 2019-03-31
- 如何正确使用开源项目? 2019-03-31
- ajax请求后台接口数据与返回值处理js的实例讲解 2019-03-31









