Calculate previous week's start and end date

前端 未结 7 1678
甜味超标
甜味超标 2020-12-13 17:41

What is the best way to calculate the previous week\'s start and end date in C#? I.e. today 18 March would result in 9 March (Monday last week) and 15 March (Sunday last we

7条回答
  •  暖寄归人
    2020-12-13 18:14

    using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime

    var dateTime = 1.Weeks().Ago();
    var monday = dateTime.Previous(DayOfWeek.Sunday);
    var sunday = dateTime.Next(DayOfWeek.Sunday);
    

提交回复
热议问题