$t = "2021-9-8";
$t_arr = explode("-", $t);
$t_1 = sprintf("%02d",$t_arr[1]);
$t_2 = sprintf("%02d",$t_arr[2]);
$t_str = $t_arr[0]."-".$t_1."-".$t_2;
echo $t_str;
2021-09-08
修改数据库数据,以下用的thinkphp6
$card = Db::table("card_content")
->page(1, 1000)
->select()->toArray();
foreach($card as $key=>$item){
$time_arr[$key] = explode("-", $item['day']);
$time_1[$key] = sprintf("%02d",$time_arr[$key][1]);
$time_2[$key] = sprintf("%02d",$time_arr[$key][2]);
$time[$key]['id'] = $item['id'];
$time[$key]['time'] = $time_arr[$key][0]."-".$time_1[$key]."-".$time_2[$key];
Db::table("card_content")
->where("id", "=", $time[$key]['id'])
->update([
"day"=>$time[$key]['time']
]);
}