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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)