angularjs 时间戳

1、目的:将后台获取的值存到一定格式的input框:


2、实现后应该是如下:


操作步骤:

1、HTML为:

 
 
<input type="date" id="startDate" class="form-control" 
name="testDate" ng-model="testDate.value" placeholder="yyyy-MM-dd" style="width:100%;"//input的html

    <input type="datetime"/>------→这个是普通的input时间框,

    <input type="datetime-local"/>这个是有分和秒的时间框:类似这种


2对应的js:


从后台获取的数据为时间戳:1403058804000


 
 
var newdate=1403058804000;

接下来需要将newdate转换为时间戳 : 

 
 
var newda=new Date();
newda.setTime(newdate)
此时
 
 
$scope.testDate = {
    value:new Date(newda.setTime(newdate))//value必须为new Date()
}
 
 

        这时运行即可实现。

二 、于此相反的是:从时间框获取数据传给后台(这里呢,后台可以处理格式转为时间戳):

 
 
var dateStart = $("#startDate").val();//从HTML中根据input的id 获取的时间值
console.log(dateStart);//输出的值为:2018-05-18
obj.negotiateTime = dateStart;//谈判时间


猜你喜欢

转载自blog.csdn.net/qq_41987575/article/details/80367333
今日推荐