使用sscanf拆分日期

时间:2015-06-23 09:52:55

标签: php

我有这样的约会

int[] t1 = new int[] { 0, 2 };
        List<int[]> trash = new List<int[]>()
        {
            t1,
            new int[] {0,2},
            new int[] {1,0},
            new int[] {1,1}
        };
        List<int[]> trash2 = new List<int[]>()
        {
            new int[] {0,1},
            new int[] {1,0},
            new int[] {1,1}
        };

        MessageBox.Show(trash.Count + "");
        trash.RemoveRange(trash2);
        MessageBox.Show(trash.Count + "");

^我正在尝试应用此2015-10-09T19:30:00 list($y, $M, $d, $h, $m, $s) = sscanf($instance->Start, "$d-$d-$dT$d:$d:$d"); 来拆分组件但我在T部分遇到错误

最终想要这样的东西

sscanf

2 个答案:

答案 0 :(得分:1)

您可以使用DateTime界面 -

$date = new DateTime('2015-10-09T19:30:00');
echo $date->format('d-m-Y').' T '.$date->format('H:i:s').' Europe/London';

<强>输出

09-10-2015 T 19:30:00 Europe/London

正确答案

echo $date->format('d-m-Y').' UTC '.$date->format('H:i:s').' Europe/London'; 

答案 1 :(得分:1)

<?php

$date = "2015-10-09T19:30:00";
$z = "Europe/London";

sscanf($date, "%d-%d-%dT%d:%d:%d", $year, $month, $day, $hours, $minutes, $seconds);

$timestamp = $day."-".$month."-".$year."T".$hours.":".$minutes.":".$seconds." ".$z;
echo $timestamp;

?>