如何计算红宝石日期中的星期几? [英] How can I calculate the day of the week of a date in ruby?

查看:116
本文介绍了如何计算红宝石日期中的星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Ruby中计算日期的星期几?例如,2010年10月28日是=星期四

How can I calculate the day of the week of a date in Ruby? For example, October 28 of 2010 is = Thursday

推荐答案

我之所以使用它,是因为我讨厌去Date文档查看

I have used this because I hated to go to the Date docs to look up the strftime syntax, not finding it there and having to remember it is in the Time docs.

require 'date'

class Date
  def dayname
     DAYNAMES[self.wday]
  end

  def abbr_dayname
    ABBR_DAYNAMES[self.wday]
  end
end

today = Date.today

puts today.dayname
puts today.abbr_dayname

这篇关于如何计算红宝石日期中的星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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