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

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

问题描述

如何计算红宝石日期的星期几?例如,2010年10月28日是=星期四

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

推荐答案

我用过这个是因为我讨厌去Date日期在strftime语法中,没有找到它,并且必须记住它在Time文档中。

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天全站免登陆