我有一个表单,其中一个输入类型为datetime-local。此表格最终通过角度上传。我想要做的是在发布之前将本地日期输入转换为utc。我似乎无法弄明白这一点。我已经尝试了几种方法,但我不断得到未定义的值。这是我试过的:
HTML:
<input type="datetime-local" ng-model="PublishStartDate"
name="PublishStartDate" class="form-control"
id="publishStartDateId" />
JavaScript的:
var formElement = document.getElementById('articleForm');
formElement.elements['PublishStartDate'].value = moment.utc(formElement.elements['PublishStartDate'].value);
var objData = new FormData(formElement);
我最终使用下面的角度代码发布表单,因为我也发送文件数据:
$http.post('/api/ArticleAdminApi/UpdateArticle', objData, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
})
答案 0 :(得分:0)
<script>
var app = angular.module('app',[]);
</script>
<input type="datetime-local" ng-model="PublishStartDate"
name="PublishStartDate" class="form-control"
id="publishStartDateId" />
{{PublishStartDate}}
浏览Plunkr:here