开发者

Rails undefined method `[]' for 2011-03-16 18:58:00 UTC:Time

开发者 https://www.devze.com 2023-02-17 02:11 出处:网络
Total newbie with ruby and rails...and perhaps I\'m making more work for myself...but unable to change the timezone to local I decided to parse the date and time and use it for my own purposes.Except

Total newbie with ruby and rails...and perhaps I'm making more work for myself...but unable to change the timezone to local I decided to parse the date and time and use it for my own purposes. Except the substring is not working out for me.

<% ds = thejob.datestamp 
       dsyy = ds[0,4]
       dsmm = ds[5,2]   
     开发者_如何学运维  dsdd = ds[8,2]   
       dshrs = ds[11,2]   
       dsmin = ds[14,2]   
       dssec = ds[17,2]   
       dstz = ds[20,2] %>

Results in error:

undefined method `[]' for 2011-03-16 18:58:00 UTC:Time


Are you sure datestamp is actually a string, rather than a Time type value?

Judging by the Ruby date/time documentation, you may just need:

local = thejob.datestamp.getlocal


ds = thejob.datestamp 
dsyy = ds.year
dsmm = ds.month   
dsdd = ds.day  
dshrs = ds.hour
dsmin = ds.min
dssec = ds.sec  
dstz = I don't remember
0

精彩评论

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