Ruby并不想格式化字符串到目前为止

时间:2017-02-17 14:56:40

标签: ruby

我需要格式化一个字符串到日期:

date = DateTime.parse("05/15/2017")
formatted_date = date.strftime('%m/%d/%Y')
puts formatted_date

但是我收到了错误:

`parse': invalid date (ArgumentError)

如果我尝试解析15/05/2017,那么它就可以了。

如何将05/15/2017解析为%m/%d/%Y格式?

1 个答案:

答案 0 :(得分:4)

这是引发错误的第一行,因为<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script type ="text/javascript"> function getModel(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","get_model.php?marca="+document.getElementById("marca").value, false); xmlhttp.send(null); document.getElementById("model_masina").innerHTML=xmlhttp.responseText; } function model_schimba(){ $modelSc = (document.getElementById("model").value); } </script> 不知道如何处理字符串?> <label for="model">Model </label> <select id="model" nume="model" onchange='model_schimba()'> <option value="">Alege Model</option> <?php while($row = mysqli_fetch_array($res)){ ?> <option value="<?php echo $row["id"] ?>"> <?php echo $row["name"] ?> </option> <?php } ?> </select> <?php } 。请改用Date.strptime告诉Ruby如何读取字符串:

Date.parse