{"pageNum":1,"pageSize":20,"size":2,"startRow":1,"endRow":2,"total":"2","pages":1,"list":[{"publicDate":"2023-05-30 03:58:36","createDate":"2023-05-30 03:58:39","orderLimitDate":"2023-06-02 03:58:36","processInstanceId":451474535276664170,"workOrderStateName":"待受理","mainClearTime":"2023-05-30 04:06:36","applyStaffId":-111,"alertDate":"2023-06-01 11:58:36","partyOrgId":4136,"ROW_ID":1,"operMode":3,"tacheId":"230203264272072704","partyNameOrg":"宿迁PS域核心网设备维护组","areaId":13,"isOvertimeDesc":"正常"},{"publicDate":"2023-05-29 21:53:36","createDate":"2023-05-29 21:53:39","orderLimitDate":"2023-06-01 21:53:36","processInstanceId":451382679343781237,"workOrderStateName":"待受理","mainClearTime":"2023-05-30 08:44:03","applyStaffId":-111,"alertDate":"2023-06-01 05:53:36","partyOrgId":2938,"ROW_ID":2,"operMode":3,"tacheId":"230203264272072704","partyNameOrg":"宿迁数据组","areaId":13,"isOvertimeDesc":"正常"}],"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1,"firstPage":1,"lastPage":1} 使用PHP语言 第一步循环遍历上面数据中publicDate值并进行时间戳转换并将值赋值个zhuanghuanh,然后将zhuanghuanh转换结果插入到原始数组中
时间: 2023-07-02 19:22:57 浏览: 128
可以使用以下代码实现:
```
$data = '{"pageNum":1,"pageSize":20,"size":2,"startRow":1,"endRow":2,"total":"2","pages":1,"list":[{"publicDate":"2023-05-30 03:58:36","createDate":"2023-05-30 03:58:39","orderLimitDate":"2023-06-02 03:58:36","processInstanceId":451474535276664170,"workOrderStateName":"待受理","mainClearTime":"2023-05-30 04:06:36","applyStaffId":-111,"alertDate":"2023-06-01 11:58:36","partyOrgId":4136,"ROW_ID":1,"operMode":3,"tacheId":"230203264272072704","partyNameOrg":"宿迁PS域核心网设备维护组","areaId":13,"isOvertimeDesc":"正常"},{"publicDate":"2023-05-29 21:53:36","createDate":"2023-05-29 21:53:39","orderLimitDate":"2023-06-01 21:53:36","processInstanceId":451382679343781237,"workOrderStateName":"待受理","mainClearTime":"2023-05-30 08:44:03","applyStaffId":-111,"alertDate":"2023-06-01 05:53:36","partyOrgId":2938,"ROW_ID":2,"operMode":3,"tacheId":"230203264272072704","partyNameOrg":"宿迁数据组","areaId":13,"isOvertimeDesc":"正常"}],"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1,"firstPage":1,"lastPage":1}';
$array = json_decode($data, true);
foreach ($array['list'] as &$item) {
$publicDate = strtotime($item['publicDate']);
$item['zhuanghuanh'] = date('Y-m-d H:i:s', $publicDate);
}
print_r($array);
```
在循环中,使用了引用符号`&`来获取原始数组中的每一项,然后使用`strtotime()`函数将`publicDate`转换为时间戳,再使用`date()`函数将时间戳转换为需要的日期时间格式,并赋值给新的键名`zhuanghuanh`。最后,使用`print_r()`函数输出转换后的原始数组。
阅读全文