Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Date#parse assume a US format instead of an EU format

Tags:

With 1.9.2p0, Date#parse assumes an UE format. Check out format.rb, line: 1042 if you don't believe me.

Anyways, how can I make it assume a US format, so that:

> Date.parse("10/4/2010")
 => Mon, 04 Oct 2010

Instead of April 10th.

I've tried this:

class Date
  def _parse_eu(str,e)
    _parse_us(str,e)
  end
end

but no luck. Any other ideas?

like image 527
jsharpe Avatar asked Sep 21 '10 02:09

jsharpe


People also ask

What does make a day mean?

: to cause someone's day to be pleasant or happy Thanks for the compliment. You've really made my day!

What is an example of a date?

Date is defined as a particularly day of the month or day, month and year or a social outing between two people. An example of date is October 9, 1925. An example of date is two people meeting for coffee.

What are Friend dates?

This, in a nutshell, is the art of 'friend dating'. The premise of friend dating is this: if we like the thought of being mates with someone, we should actively pursue and nurture a relationship with them, much in the same way we might treat a potential romantic partner.

What is the synonym of date?

nounarrangement for meeting; prearranged meeting. assignation. assignment. blind date. consultation.


2 Answers

Date.strptime is what you want but unfortunately it doesn't look like the documentation has the date formatting strings. I got the following to work based on Googling for the format strings:

1.9.2 > d = Date.strptime("10/4/2010", "%m/%d/%Y")
=> #<Date: 2010-10-04 (4910947/2,0,2299161)> 
1.9.2 > d.day
=> 4 
1.9.2 > d = Date.strptime("10/4/2010", "%d/%m/%Y")
=> #<Date: 2010-04-10 (4910593/2,0,2299161)> 
1.9.2 > d.day
=> 10
like image 107
Jason Avatar answered Oct 05 '22 19:10

Jason


You might want to check out strptime instead.

like image 24
Dean Harding Avatar answered Oct 05 '22 20:10

Dean Harding