Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
日期格式转换ruby_Ruby_Datetime_Date - Fatal编程技术网

日期格式转换ruby

日期格式转换ruby,ruby,datetime,date,Ruby,Datetime,Date,我认为这说明了一切: irb(main):014:0> DateTime.strptime("4/23/1967", "%m/%d/%y").to_s => "2019-04-23T00:00:00+00:00" 2019年就要到了 我有两种不同的日期格式: 1967年4月23日 3-3-1985 我想将它们都标准化,以第一种格式显示(带斜杠)。您的问题是您编写了%y,您的意思是%y。日期格式字符串区分大小写 irb(main):014:0> DateTime.strptim

我认为这说明了一切:

irb(main):014:0> DateTime.strptime("4/23/1967", "%m/%d/%y").to_s
=> "2019-04-23T00:00:00+00:00"
2019年就要到了

我有两种不同的日期格式:

1967年4月23日

3-3-1985


我想将它们都标准化,以第一种格式显示(带斜杠)。

您的问题是您编写了
%y
,您的意思是
%y
。日期格式字符串区分大小写

irb(main):014:0> DateTime.strptime("4/23/1967", "%m/%d/%y").to_s
=> "2019-04-23T00:00:00+00:00"
但是


你的问题是你写了
%y
,意思是
%y
。日期格式字符串区分大小写

irb(main):014:0> DateTime.strptime("4/23/1967", "%m/%d/%y").to_s
=> "2019-04-23T00:00:00+00:00"
但是


%y
以2位数字表示年份,因此为19。然后DateTime假设是2019年。您需要
%Y
%Y
以2位数字表示年份,因此为19。然后DateTime假设是2019年。您需要
%Y