开发者

How do I convert **Object.days = 256 days** to **256**

@days_since_last_payment = 256 days

How do I derive the number 256 out of this? It seems if I use a math operation on this, it calculates something other than 256.

It is derived from

@days_since_last_payment = (Date.parse(@d开发者_开发百科ate_awarded) - Date.parse(@date_paid)).days


I assume you meant 256.days rather than 256 days. If so, you can divide by 86400 to get the actual number 256. (It looks like 256.days is actually stored as 22,118,400 seconds)

ruby-1.9.2-p136 :056 > @days_since_last_payment
 => 256 days 
ruby-1.9.2-p136 :057 > @days_since_last_payment.seconds
 => 22118400 seconds 
ruby-1.9.2-p136 :058 > @days_since_last_payment.to_i
 => 22118400 
ruby-1.9.2-p136 :059 > @days_since_last_payment / 86400
 => 256 


regex. I don't know Ruby, but take a look at http://www.regular-expressions.info/ruby.html

Basically, you can remove all non-digits by replacing /\D+/gi with ''.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜