Ruby code to get the date of next Monday (or any day of the week)

前端 未结 7 472
再見小時候
再見小時候 2020-12-02 14:36

Given an input of, for example,

day = \'Monday\'

how can I calculate the date of day?

def date_of_next(day)
           


        
相关标签:
7条回答
  • 2020-12-02 15:15

    Rails >= 5.2.3

    Date.current.next_occurring(:monday)
    

    https://api.rubyonrails.org/classes/DateAndTime/Calculations.html#method-i-next_occurring

    0 讨论(0)
提交回复
热议问题