ruby 日期时间中有 add_days 吗? [英] Is there an add_days in ruby datetime?

查看:16
本文介绍了ruby 日期时间中有 add_days 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中,DateTime 类中有一个 AddDays([number of days]) 方法.

In C#, There is a method AddDays([number of days]) in DateTime class.

ruby 有没有这样的方法?

Is there any kind of method like this in ruby?

推荐答案

Date 类提供了一个 + 运算符来实现这一点.

The Date class provides a + operator that does just that.

>> d = Date.today
=> #<Date: 4910149/2,0,2299161>
>> d.to_s
=> "2009-08-31"
>> (d+3).to_s
=> "2009-09-03"
>> 

这篇关于ruby 日期时间中有 add_days 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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