Class: String
Instance Method Summary collapse
-
#del_inter ⇒ Object
清除干扰数据 清除包含: 空格,回车.
-
#to_time ⇒ Object
转换成时间格式.
Instance Method Details
#del_inter ⇒ Object
清除干扰数据 清除包含: 空格,回车
5 6 7 |
# File 'lib/http_crawler/common/string.rb', line 5 def del_inter self.gsub(/(?:\n|\t|\r| | )/, "") end |
#to_time ⇒ Object
转换成时间格式
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/http_crawler/common/string.rb', line 10 def to_time # 然后再遍历 [ "%Y年%m月%d日%H:%M:%S", "%Y年%m月%d日 %H:%M:%S", "%Y年%m月%d日%H:%M", "%Y年%m月%d日 %H:%M", "%Y-%m-%d%H:%M:%S", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d%H:%M", "%Y-%m-%d %H:%M", "%Y-%m-%d", "%Y年%m月%d日", "%Y%m%d", "%Y%m%d%H%M%S", "%Y%m%d%H%M", ].each do |v| begin return Time.strptime(self, v) rescue => error end end Time.at(self.to_i / 1000.0) if self.length == 13 Time.at(self.to_i) if self.length == 10 # 最后用 Time通用类型尝试 return Time.parse(self) end |