dayjs 常用的日期配置,相差八小时,月初至月末,本周初至本周末
分类专栏: Node
简介 有时候获取时间会有时间差,相差八小时;获取本月起至本月末的时间,本周起至本周末的时间;
<pre class="ql-syntax" spellcheck="false">npm install dayjs --save
const dayjs = require("dayjs");
var utc = require("dayjs/plugin/utc");
dayjs.extend(utc);
</pre><p><br></p><pre class="ql-syntax" spellcheck="false">// utcOffset 偏移八小时
dayjs().utcOffset(8).format("YYYY年MM月DD HH:mm")
</pre><p><br></p><pre class="ql-syntax" spellcheck="false">
const nowZero = new Date().setHours(0, 0, 0, 0);
// 本周的起点
starttime = moment(nowZero).weekday(1).format();
// 本周的终点
endtime = moment(nowZero).weekday(8).format();
_time = { $gte: starttime, $lte: endtime }
</pre><p><br></p><pre class="ql-syntax" spellcheck="false"> let _date = moment().utcOffset(8).format('YYYY-MM-DD HH:mm:ss');
// 本月的起点
startTime = moment(_date).startOf('month').format('YYYY-MM-DD');
// 本月的终点
endTime = moment(_date).endOf('month').format('YYYY-MM-DD');
</pre><p><br></p>
分享到:
转载:
喜欢 1
收藏
暂无评论信息
- 相关文章
- 文章推荐
- 点击排行
- 站长推荐
- 猜你喜欢
- 网站信息
- 站内问答:12篇
- 站内文章:213篇
- 建站时间:已运行1243天
- 备案号: 浙ICP备2022018799号
- 语言:
- English(USA)
- French(FR)
- Chinese(ZH)
无数据