用原生js获取当前日期以及三十天前日期的方法
js处理——获取当前月第一天和最后一天
getCurrentMonthTime(){
const date = new Date();
// 设置为日期1号
date.setDate(1);
// 获取当前月份(date.getMonth()返回的是0-11)
let month = parseInt(date.getMonth() + 1);
// 获取当月第一天日期
let startDay = date.getDate();
// 获取当前月的最后一天。参数0代表上个月的最后一天
const endOfMonth = new Date(date.getFullYear(), month, 0).getDate();
// 设置日期为当前月的最后一天
date.setDate(endOfMonth);
// 获取当月最后一天日期
let endDay = date.getDate();
if (month < 10) month = '0' + month
if (startDay < 10) startDay = '0' + startDay
if (endDay < 10) endDay = '0' + endDay
const startTime = date.getFullYear() + '-' + month + '-' + startDay + " " + "08:00:00";
const endTime = date.getFullYear() + '-' + month + '-' + endDay + " " + "08:00:00";
return [startTime,endTime]
},
获取太平洋时间
美国西部采用的是太平洋标准时间PST,可利用js将北京时间转换成PST 时间。
var t = new Date().getTime();
t = t - 15 * 3600 * 1000; //如果美国是夏令时,与北京时间差15小时;如果是冬令时,相差16小时
t = new Date(t); //忽略t显示的时区,则t就表示美国PST时间。
————————————————
版权声明:本文为优快云博主「monkey_four」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/monkey_four/article/details/49077557