我用 sidekiq 从一个 API 获取到两个字段,都是字符串。 一个是日期 "2012-09-09" 一个是时间"13:34:09" 然后我用
DateTime.strptime("#{@records[30]} #{@records[31]}", '%Y-%m-%d %H:%M:%S')
或者
DateTime.parse("#{@records[30]} #{@records[31]}")
转换成时间格式,然后保存到数据库,
class xxx
field :got_at, :type => DateTime
end
但是都出现这个错误
012-12-15T12:27:44Z 1077 TID-owuatkq7w StockspiderWorker MSG-owua5ch64 INFO: fail: 0.633 sec
2012-12-15T12:27:44Z 1077 TID-owuatkq7w WARN: invalid date
2012-12-15T12:27:44Z 1077 TID-owuatkq7w WARN: /Users/stephen/Gupiao/app/workers/stockspider_worker.rb:17:in `strptime'
/Users/stephen/Gupiao/app/workers/stockspider_worker.rb:17:in `block in perform'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual/mongo.rb:672:in `yield_and_increment'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual/mongo.rb:134:in `block (2 levels) in each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/query.rb:78:in `block in each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/cursor.rb:26:in `block in each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/cursor.rb:26:in `each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/cursor.rb:26:in `each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/query.rb:77:in `each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/moped-1.1.6/lib/moped/query.rb:77:in `each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual/mongo.rb:133:in `block in each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual/mongo.rb:632:in `selecting'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual/mongo.rb:132:in `each'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/mongoid-3.0.1/lib/mongoid/contextual.rb:18:in `each'
/Users/stephen/Gupiao/app/workers/stockspider_worker.rb:8:in `perform'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/processor.rb:36:in `block (3 levels) in process'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:75:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:75:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/timeout.rb:14:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:77:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:77:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/retry_jobs.rb:30:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:77:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/logging.rb:22:in `with_context'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:77:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/server/exception_handler.rb:9:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:77:in `block in invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:80:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/middleware/chain.rb:80:in `invoke'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/processor.rb:35:in `block (2 levels) in process'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/processor.rb:66:in `stats'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/sidekiq-1.2.1/lib/sidekiq/processor.rb:34:in `block in process'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/celluloid-0.10.0/lib/celluloid/calls.rb:56:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/celluloid-0.10.0/lib/celluloid/calls.rb:56:in `dispatch'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/celluloid-0.10.0/lib/celluloid/future.rb:18:in `block in initialize'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/celluloid-0.10.0/lib/celluloid/thread_pool.rb:46:in `call'
/Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/celluloid-0.10.0/lib/celluloid/thread_pool.rb:46:in `block in create'
但是在 rails c 运行,没有出现这个错误。 应该要怎么解决?