如何将值从字符串转换为日期以保存数据?

时间:2018-03-21 08:27:28

标签: html

我无法在数据库中存储日期值,如果它的字符串,我怎样才能将其转换为日期格式?

<div class='input-group date' id='datetimepicker1'>
    <input type='text' id="startDate" data-bind="value: startDate()" class="form-control" />
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
    <span class="input-group-addon">
        <span onclick="startToday()">Today</span>
    </span>
</div>

1 个答案:

答案 0 :(得分:0)

正确的方法是使用http://www.mapquestapi.com/geocoding/v1/address?key=your_key_here&location=Easton,PA&outFormat=xml&maxResults=1 并使用JavaScript Date Object

转换它

&#13;
&#13;
<input type="date">
&#13;
function parse() {
  var startDate = document.getElementById("startDate").value.split("-");

  var date;
  if (startDate.length == 3) date = new Date(startDate[0], startDate[1], startDate[2]);
  else date = new Date();

  console.log("Formated:", date);
  console.log("Timestamp:", date.valueOf() / 1000);
}
&#13;
&#13;
&#13;