Mac Excel日期- Ruby编码



我有Mac Excel,并试图在ruby中解析日期。Excel有一个类似12/10/11的格式。我想把它写成12/10/11的ruby格式。现在当我用

解析Excel时
@book = Spreadsheet::ParseExcel.parse("..path")
sheet1 = @book.worksheet(1)
@number = sheet1.count
@abc = ""
sheet1.each do |cell|
    @hello = cell.to_s.match(/A[+-]?d+?(.d+)?Z/) == nil ? true : false // if numeric
       if @hello == true
      // Trying to parse date into actual date without getting float...(Help needed)
     else     
        @abc += cell.join(',')+"*"
end
end
puts @abc

有谁能帮我做这个转换吗?

只要调用to_time,它就会给你一个DateTime对象,你可以在Ruby中使用它。下面是一个使用rails控制台的示例:

> "12/10/11".to_time
=> Thu, 10 Dec 0011 00:00:00 +0000

我可以解决这个…我打过电话。我从excel中提取的每个单元格的日期,并解决了它…谢谢你的帮助…我还有一个问题…我试图在html动词中使用javascript变量。就像在<% %>标签..query[i]是我在循环中的东西我正在打电话& lt; % = Table.update(查询[我])%>;我怎么能有查询[I]从javascript是实际值?

最新更新