js 时间转换( 时间戳 & 标准时间 &格式化后日期)
发布时间
阅读量:
阅读量
ion-datetime-picker地址:
https://github.com/katemihalikova/ion-datetime-picker
注: 时间戳不能get年月日时分秒, new Date(时间戳).get年月日时分秒
时间戳 ==> YYYY-MM-DD HH:MM:SS
let date = new Date(value); //转成标准时间,
//才能 getFullYear()、getMonth() 、getDate()
let y = date.getFullYear();
let MM = date.getMonth() + 1;
MM = MM < 10 ? ('0' + MM) : MM;
let d = date.getDate(); d = d < 10 ? ('0' + d) : d;
let h = date.getHours(); h = h < 10 ? ('0' + h) : h;
let m = date.getMinutes(); m = m < 10 ? ('0' + m) : m;
let s = date.getSeconds(); s = s < 10 ? ('0' + s) : s;
return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
时间戳 ==> 标准时间
new Date(时间戳);
YYYY-MM-DD HH:MM:SS ==> 时间戳
new Date().getTime()
new Date( 'YYYY-MM-DD' ).getTime()
中国标准时间 =转=> 时间戳
new Date().getTime() //当天时间戳
new Date('2020-03-09').getTime() //某天时间戳
设置某天时间 :
`setDate(1)`
//如:
new Date('2020-02-09').setDate(1) //1580515200000
下面是例子:
new Date('2020-03-09').getTime() //1583712000000
new Date(1583712000000) //时间戳转 中国标准时间
new Date('2020-03-09')
//Mon Mar 09 2020 08:00:00 GMT+0800 (中国标准时间)
new Date('2020-02-09').setDate(1) //1580515200000
new Date(new Date('2020-02-09').setDate(1))
//Sat Feb 01 2020 08:00:00 GMT+0800 (中
国标准时间)
在between时间内, 选择
only-valid="{‘between’: {‘initial’: startDate, ‘final’: beforeDate}}"
在outside时间内, 选择:
only-valid="{‘outside’: {‘initial’: startDate, ‘final’: beforeDate}}"
可以多段outside时间:
only-valid="[{‘after’: ‘2017-01-12’}, {‘outside’: {‘initial’:
‘2017-01-19’, ‘final’: ‘2017-01-29’}}, {‘outside’: {‘initial’:
‘2017-02-19’, ‘final’: ‘2017-02-29’}}]"
全部评论 (0)
还没有任何评论哟~
