html、js、django处理日期问题

在html中使用日期控件,利用ngmodel将输入的值传到js里:

1 <input type="date" ng-model="timeOps.test.a_time">

关于其他与时间有关的控件介绍:http://blog.csdn.net/u014063717/article/details/50914466

 

在js里接收数据,可以利用$filter对日期的格式进行处理

 1 $scope.timeOps = {
 2   test: {
 3                 a_time: new Date()   //用Date对象接收数据 
 4         }
 5 }
 6 
 7 
 8 $scope.downloadInterior = function () {
 9   $scope.start_time = $filter('date')($scope.timeOps.test.time, 'yyyy-MM-dd');
10         //$filter('date')将html的数据转为类似2017-08-06的格式
11 }    

也可以转换为其他的格式,具体的方法可以参照下面网址,其中也有在html中对日期格式的处理实例

http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/angularjs%E4%B8%AD%E7%9A%84filter-%E8%BF%87%E6%BB%A4%E5%99%A8-%E6%A0%BC%E5%BC%8F%E5%8C%96%E6%97%A5%E6%9C%9F%E7%9A%84date/

补充一下  利用filter转换时,貌似yyyy-MM-dd HH:mm:ss格式为24小时制,yyyy-MM-dd hh:mm:ss格式为12小时制

1 $scope.start_time = $filter('date')($scope.timeOps.test.time.setHours(0,0,0), 'yyyy-MM-dd HH:mm:ss');
2 $scope.start_time = $filter('date')($scope.timeOps.test.time.setHours(0,0,0), 'yyyy-MM-dd hh:mm:ss');

第一行代码得到的结果是2017-08-07 00:00:00;第二行代码得到的是2017-08-07 12:00:00

 

处理过格式的日期数据在django后台就可以使用GET方法接收到了,可以与django数据库中的models.DateTimeFiled属性比较并进行过滤等操作

具体的过滤操作可以参照:http://blog.csdn.net/huanongjingchao/article/details/46910521

posted @ 2017-08-06 22:43  Infinite666  阅读(1223)  评论(0编辑  收藏  举报