我使用的是Asp.net core MVC 3.1,我需要编辑我的代码。我找了很多,但没有找到解决我问题的方法。首先,我有一个列类型 "datetime "的数据是这样的 "2020-01-01 14:22:00.000 "在SqlServer中。
当把这些值上传到输入时,我得到了以下的错误信息。
"输入字符串的格式不正确。"
以下是我的index.cshtml代码。
<div class="form-group">
<label asp-for="shift_to" class="control-label"></label>
<input class="shift_to" asp-for="shift_to" type="datetime-local" />
<span asp-validation-for="shift_to" class="text-danger"></span>
</div>
Javascript:
function calculate() {
var startTime = $('.shift_from')[0].value;
var endTime = $('.shift_to')[0].value;
return (new Date(endTime) - new Date(startTime)) / 1000 / 60 / 60;
}
$('.shift_to').change(function () {
$('.shift_hours').val(calculate());
});
该
FORMAT()
功能还可以让你 日期和时间格式 在SQL Server中。
比如说,如果你需要在JavaScript中格式化日期
FORMAT(Created, 'dd.mm.yyyy HH:mm') AS DateCreated
--08.24.2019 14:24
如果你需要在JavaScript中格式化日期。
const date = new Date(2019, 0, 23, 17, 23, 42)
toString // Wed Jan 23 2019 17:23:42
toDateString // Wed Jan 23 2019
toLocaleString // 23/01/2019, 17:23:42
toLocaleDateString // 23/01/2019
toGMTString // Wed, 23 Jan 2019 09:23:42 GMT
toUTCString // Wed, 23 Jan 2019 09:23:42 GMT
toISOString // 2019-01-23T09:23:42.079Z
希望能帮到你