ajax json 时间戳日期

ajax json 时间戳日期

封装部分

<script>
	const formatTime = (timestamp) => {
		var date = new Date(timestamp*1000)
		const year = date.getFullYear()
		const month = date.getMonth() + 1
		const day = date.getDate()
		const hour = date.getHours()
		const minute = date.getMinutes()
		const second = date.getSeconds()
		return [year, month, day].map(formatNumber).join('-')
	}
	const formatNumber = n => {
		n = n.toString()
		return n[1] ? n : '0' + n
	}
</script>

ajax html部分

<script>
	$("#district_id").change(function(){
		var district_id=$(this).val();
		$.ajax({
			url:'/Get/get_time',
			Type:"POST",
			data:"time="+time,
			dataType:"json",
			success:function(data){
				var daili = data.daili;
				$('.table tr:gt(0)').remove();//删除之前的数据
				$.each(daili,function(i,result){
					item = "<br><table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"0\"><tr><td style=\"text-align:center;\">授权结束</td><td style=\"text-align:center;\">"+formatTime(result['time'])+"</td></tr></table><br>";
					$('.table').append(item);
				});
			}
		});
	});
</script>

php后台部分

    public function get_time(){
        $listObj = M('time_list');//定义数据表
        $where['district'] = I('district_id');//ajax post传值
        $list = $listObj->where($where)->select();//数据库查询
        $data=array('status'=>0,'time'=>$list);//列出数据组
        header("Content-type: application/json");//json输出声明
        exit(json_encode($data));//输出格式json
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值