Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a difference between Datetime.civil and Datetime.new in ruby?

Tags:

ruby

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 ?

like image 813
alexserver Avatar asked Nov 09 '12 05:11

alexserver


People also ask

What is DateTime 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.

How do I change the date format in Ruby?

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.

How do you parse a date in Ruby?

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.


2 Answers

According to the documentation, they are the same. Also:

DateTime.method(:new) == DateTime.method(:civil)
=> true
like image 75
davidrac Avatar answered Nov 13 '22 14:11

davidrac


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

like image 35
vijikumar Avatar answered Nov 13 '22 13:11

vijikumar