如何在打字稿中查找从今天的日期开始的星期六和星期日的日期? [英] How to find the dates of coming saturday and sunday from today's date in typescript?

查看:55
本文介绍了如何在打字稿中查找从今天的日期开始的星期六和星期日的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中设置了今天的日期,

I have set today's date in code as follows,

 public fromDate: Date = new Date();

我如何找到周六和周日的日期,这意味着这个周末是从上述日期开始的?

How can i find the dates of coming saturday and sunday, mean this weekend dates from the above?

我可以尝试添加当天的天数.但是有更好的解决方案吗?

i can try by adding number of days from the current day. but is there a better solution?

推荐答案

如果您不介意使用外部库,则可以使用 moment

If you don't mind using an external library, you can use moment's day function.

import * as moment from 'moment';
const fromDate = moment();
const nextSunday = fromDate.day(7);
console.log(nextSunday.calendar());

这篇关于如何在打字稿中查找从今天的日期开始的星期六和星期日的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆