0

在解析包含日期(例如 13/Nov/11)的 Jira 自定义字段时,我从以下内容开始:

elsif custom.customfieldId == "customfield_10282"
@agenda_item.planned_release_date      =  custom.values.to_s

但数据库将其存储为 11/13/0011。所以我变得聪明并使用了这个:

elsif custom.customfieldId == "customfield_10282"
@agenda_item.planned_release_date      =  Date.strptime(custom.values, "%d/%m/%Y")

现在我得到:

私有方法sub!' called for ["15/Nov/11"]:Jira4R::V2::ArrayOf_xsd_string C:/Ruby187/lib/ruby/1.8/date/format.rb:429:in_strptime_i' C:/Ruby187/lib/ruby/1.8/date/format.rb:401:in scan' C:/Ruby187/lib/ruby/1.8/date/format.rb:401:in_strptime_i' C:/Ruby187/lib/ruby/1.8/date/format.rb:601:in `_strptime' [截断堆栈的其余部分]

我错过了什么?

4

2 回答 2

2

如果我正确理解您的问题,请尝试使用:

Date.strptime('13/Nov/11', "%d/%b/%y")  # => 2011-11-13

你有缩写的月份名称,你应该使用b格式指令。除此之外,因为您的年份仅包含最后两个数字,请使用y指令。

于 2011-11-11T21:05:13.043 回答
2

这有效:

p Date.strptime('13/Nov/11', "%d/%b/%y")

你的问题:

  • `%Y是 4 位数字 ( 2011) 的年份。采用%y
  • %m是以数字表示的月份 ( 11)。改用%b( Nov)
于 2011-11-11T21:05:47.117 回答