dtmu88600 2015-12-01 15:46
浏览 41
已采纳

Angularjs只在php中输出时间来自html输入时间属性

I want to save from HTML to PHP via Angularjs the value of "time" attribute.

In my HTML i have :

<input type="time" ng:model="stime.val" ng:value="stime.val | date: 'HH:mm:ss'" >

In the controller :

$scope.stime = { val: new Date(1970, 0, 1, 09, 00, 00) };
$scope.sendtime = [{ 'time'  : $scope.stime }];
http({ method: 'POST', url: '../index.php',
       data : $.param({ 'sendTime' : $scope.sendtime, 
                        'type' : 'post_time'
                }),
       headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success( cut off code...

In PHP :

header("Content-Type: application/json; charset=utf-8");
$postResponse = file_get_contents("php://input");
json_decode($postResponse);
if($_POST['type'] == 'post_time')
    { 
       $startTime = $_POST['sendTime']['val']; 
       print_r($startTime); 
    }

The returned data is ( let's say i input "15:06:04" )

Tue Dec 01 2015 15:06:04 GMT+0000 (GMT Standard Time)

My Question is, how can i make it to return just the time from HTML?

Something like this..

15:06:04
  • 写回答

1条回答 默认 最新

  • dsbgltg159136540 2015-12-01 18:30
    关注

    You can use the same filter in the controller in this way:

    console.log( $filter('date')( $scope.stime.val, 'HH:mm:ss' ) );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题