What is wrong with Date.parse
method?
str = "Tue, 10 Aug 2010 01:20:19 -0400 (EDT)" date = Date.parse str => #<Date: 4910837/2,0,2299161> puts date 2010-08-10
It seems to work.
The only problem here is time zone. If you want date in UTC time zone, then it is better to use Time
object, suppose we have string:
str = "Tue, 10 Aug 2010 01:20:19 +0400" puts Date.parse str 2010-08-10 puts Date.parse(Time.parse(str).utc.to_s) 2010-08-09
I couldn’t find simpler method to convert Time
to Date
.
Related Posts:
- Rails 5 ActionController::InvalidAuthenticityToken error
- what does ? ? mean in ruby
- Rails 4 RoutingError: No Route Matches
- PG::ConnectionBad – could not connect to server: Connection refused
- Rails syntax error : unexpected keyword_ensure, expecting end-of-input
- Ruby: What is the easiest way to remove the first element from an array?
- Uploading a file in Rails
- Get underlined text with Markdown
- What is the meaning of *nix?
- Get underlined text with Markdown
- How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”
- Compare two dates with JavaScript
- Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000?
- What does the “map” method do in Ruby?
- How to write a switch statement in Ruby
- Add days to JavaScript Date
- How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?
- What does %w(array) mean?
- How to use “gets” and “gets.chomp” in Ruby
- Getting a substring in Ruby by x number of chars
- How to check whether a string contains a substring in Ruby
- Add days to JavaScript Date
- Converting string to Date and DateTime
- Ruby: How to install a specific version of a ruby gem?
- Parsing XML with Ruby
- ruby operator “=~” [duplicate]
- Unable to install gem – Failed to build gem native extension – cannot load such file — mkmf (LoadError)
- What is attr_accessor in Ruby?
- ActionController::UnknownFormat
- What does ||= (or-equals) mean in Ruby?
- How to read lines of a file in Ruby
- Array to Hash Ruby
- Compare given date with today
- Ruby: undefined method `[]’ for nil:NilClass when trying to get Enumerator on an Array of Hashes
- How to map with index in Ruby?
- warning: constant ::Fixnum is deprecated When generating new model
- Ruby equivalent for Python’s “try”?
- Validate date in dd/mm/yyyy format using JQuery Validate
- What does “+=” (plus equals) mean?
- How to sum array of numbers in Ruby?
- How to check if a value exists in an array in Ruby
- undefined method (NoMethodError) ruby
- Multi-Line Comments in Ruby?
- How to uninstall ruby installed by ruby-install
- Query to convert from datetime to date mysql
- Removing all installed Gems and starting over
- How to convert an Instant to a date format?
- Ruby `send` vs `call` method
- What is the meaning of “do | |” in Ruby?
- RVM is not a function, selecting rubies with ‘rvm use …’ will not work
- How to delete specific characters from a string in Ruby?
- bcrypt LoadError: Cannot load such file
- Uninitialized constant “Controller Name”
- Ruby: kind_of? vs. instance_of? vs. is_a?
- Rails: I installed Ruby, now “bundle install” doesn’t work
- How to do a newline in output
- How do I format datetime in rails?
- Convert normal date to unix timestamp
- p vs puts in Ruby
- Determining type of an object in ruby
- Difference between rake db:migrate db:reset and db:schema:load
- Fizz Buzz in Ruby for dummies
- Check time difference in Javascript
- How to Uninstall RVM? [duplicate]
- What is the “right” way to iterate through an array in Ruby?
- TypeError: no implicit conversion of Symbol into Integer
- What is the difference between a Process’ pid, ppid, uid, euid, gid and egid?
- Equivalent of “continue” in Ruby
- What does the Ruby method ‘to_sym’ do?
- Difference between map and collect in Ruby?
- An unhandled lowlevel error occurred. The application logs may have details
- Rails button_to vs. HTML Button Tag
- Creating and iterating a 2d array in Ruby
- GROUP BY and COUNT using ActiveRecord
- What is the best way to convert an array to a hash in Ruby
- Purge or recreate a Ruby on Rails database
- Ruby 2.0.0p0 IRB warning: “DL is deprecated, please use Fiddle”
- Creating a range of dates in Python
- Getting error: dyld: Symbol not found: _clock_gettime
- Uninstall old versions of Ruby gems
- Migrations are pending; run ‘bin/rake db:migrate RAILS_ENV=development’ to resolve this issue
- What is java interface equivalent in Ruby?
- Sort hash by key, return hash in Ruby
- Gem installation error: You have to install development tools first
- An error occurred while installing json (1.8.1), and Bundler cannot continue – Rails
- How to understand strptime vs. strftime
- Nginx error: client intended to send too large body
- How can I delete one element from an array by value
- How to break out from a ruby block?
- How do I parse JSON with Ruby on Rails? [duplicate]
- ERROR: While executing gem … (Gem::FilePermissionError)
- No such file or directory @ rb_sysopen ruby
- Get integer value of the current year in Java
- How to add to an existing hash in Ruby
- Ruby ‘require’ error: cannot load such file
- How to convert a string to lower or upper case in Ruby
- Difference between $stdout and STDOUT in Ruby
- How to convert java.util.Date to java.sql.Date?
- No implicit conversion of String into Integer (TypeError)?
- Multi-Line Comments in Ruby?