如何获得下周日的日期? [英] How to get the date of the next Sunday?

查看:115
本文介绍了如何获得下周日的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   ASP.net拿到下周二

由于月中的某一天,我怎样才能从那天起,下个星期天?

Given a day of the month, how can I get the next sunday from that day?

所以,如果我通过在星期二2011年9月13号,它将返回9月18日。

So if I pass in Tuesday September 13th 2011, it will return Sept. 18th.

推荐答案

我用这个扩展方法:

    public static DateTime Next(this DateTime from, DayOfWeek dayOfWeek)
    {
        int start = (int)from.DayOfWeek;
        int target = (int)dayOfWeek;
        if (target <= start)
            target += 7;
        return from.AddDays(target - start);
    }

这篇关于如何获得下周日的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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