Hello i've been searching in the internet and seeing that there are many aliases for ruby methods doing the same (i don't know why) so i'm confused, is there a difference between Datetime.civil and Datetime.new in ruby ?
Ruby | DateTime new() function DateTime#new() : new() is a DateTime class method which returns a DateTime object denoting the given calendar date. Return: a DateTime object denoting the given calendar date.
You need to convert your string into Date object. For that, use Date#strptime . You can use Date#strftime to convert the Date object into preferred format.
Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Return: given representation of date and time, and creates a DateTime object.
According to the documentation, they are the same. Also:
DateTime.method(:new) == DateTime.method(:civil)
=> true
The calendar date is a particular day of a calendar year, identified by its ordinal number within a calendar month within that year.
In those classes, this is so-called “civil”.
Please look in to this .. http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/DateTime.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With