如何更改数组中的日期格式
print_r($data);
[01] => Array
(
[status] => Pending
[number] => 123
[DESCRIPTION] => description
[STARTDATE] => 1544079879
[RESTOREDATETIME] => 1544080492
)
我想更改日期格式
$data = $my->getCustFunction();
header("Content-Type: application/json");
print json_encode($data);
return;
我要这样回来
[01] => Array
(
[status] => Pending
[number] => 123
[DESCRIPTION] => description
[STARTDATE] => 1544079879(d/m/y)
[RESTOREDATETIME] => 1544080492
)
答案 0 :(得分:1)
这里是:
Sub x()
Dim N As Long
Dim wsName As String
For N = 1 To ThisWorkbook.Sheets.Count
wsName = ThisWorkbook.Worksheets(N).Name
If Len(wsName) = 3 Then
'command
blank wsName
hide wsName
End If
Next N
End Sub
Sub blank(s As String)
Worksheets(s).Range("T2:T6999").FormulaR1C1 = "=IF(RC[-3]<>"""",RC[-2]="""",""FALSE"")"
End Sub
Sub hide(s As String)
Worksheets(s).Columns("T:T").EntireColumn.Hidden = True
End Sub
[UPDATE]
您的数组:
$data['01']['STARTDATE'] = date("d/m/y", $data['01']['STARTDATE']);
遍历数组项并将STARTDATE转换为“ d / m / y”格式
通过“引用传递”:
$data = [
'01' => [
'status' => 'Pending',
'number' => 123,
'DESCRIPTION' => 'description',
'STARTDATE' => 1544079879,
'RESTOREDATETIME' => 1544080492,
]
];
print_r($d);
请注意foreach语句中的'&',如果没有它,您将无法在循环(http://php.net/manual/en/language.references.pass.php)内更改foreach ($data as &$item) {
$item['STARTDATE'] = date("d/m/y", $item['STARTDATE']);
}
具有“经典”风格:
$item
日期格式参数:
根据{{3}}
d-每月的某天,前两位为零的数字
m-一个月的数字表示,前导零
y-一年的两位数表示形式
/-分隔符
答案 1 :(得分:1)
假设您有多个子数组:
foreach($data as $key => $value)
{
$data[$key]['STARTDATE'] = date('d/m/y',$value['STARTDATE']);
}
答案 2 :(得分:1)
尝试
在获取数据且返回数据之前,请使用此代码
date('d/m/y', 1544079879);
到您的STARTDATE
字段
下方环绕
foreach($data as $key => $value)
{
$data[$key]['STARTDATE'] = date('d/m/y',$value['STARTDATE']);
}