本文簡要介紹ruby語言中  DateTime.parse  的用法。
用法
parse(string='-4712-01-01T00:00:00+00:00'[, comp=true[, start=Date::ITALY]], limit: 128) → datetime
解析給定的日期和時間表示,並創建一個 DateTime  對象。
此方法*不*用作驗證器。如果輸入字符串與有效格式不嚴格匹配,您可能會得到一個神秘的結果。應考慮盡可能使用“DateTime.strptime”而不是這種方法。
如果可選的第二個參數為真並且檢測到的年份在“00” 到“99” 的範圍內,則使其滿。
DateTime.parse('2001-02-03T04:05:06+07:00')
                          #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
DateTime.parse('20010203T040506+0700')
                          #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
DateTime.parse('3rd Feb 2001 04:05:06 PM')
                          #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
當字符串長度超過 limit 時,引發  ArgumentError  。您可以通過傳遞 ‘limit: nil’ 來停止此檢查,但請注意,解析可能需要很長時間。
相關用法
- Ruby DateTime.hour用法及代碼示例
 - Ruby DateTime.jd用法及代碼示例
 - Ruby DateTime.zone用法及代碼示例
 - Ruby DateTime.second用法及代碼示例
 - Ruby DateTime.second_fraction用法及代碼示例
 - Ruby DateTime.sec用法及代碼示例
 - Ruby DateTime.xmlschema用法及代碼示例
 - Ruby DateTime.iso8601用法及代碼示例
 - Ruby DateTime.now用法及代碼示例
 - Ruby DateTime.ordinal用法及代碼示例
 - Ruby DateTime.rfc3339用法及代碼示例
 - Ruby DateTime.httpdate用法及代碼示例
 - Ruby DateTime.rfc2822用法及代碼示例
 - Ruby DateTime.minute用法及代碼示例
 - Ruby DateTime.strftime用法及代碼示例
 - Ruby DateTime.sec_fraction用法及代碼示例
 - Ruby DateTime.jisx0301用法及代碼示例
 - Ruby DateTime.new_offset用法及代碼示例
 - Ruby DateTime.civil用法及代碼示例
 - Ruby DateTime.to_s用法及代碼示例
 - Ruby DateTime.min用法及代碼示例
 - Ruby DateTime.commercial用法及代碼示例
 - Ruby DateTime.strptime用法及代碼示例
 - Ruby DateTime.offset用法及代碼示例
 - Ruby DateTime jisx0301()用法及代碼示例
 
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 DateTime.parse。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
