Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用日期字符串中的两个Delimeter进行分解_Php - Fatal编程技术网

Php 使用日期字符串中的两个Delimeter进行分解

Php 使用日期字符串中的两个Delimeter进行分解,php,Php,我有一根绳子 $string="2012-1-12 51:00:00.5"; 如果不使用日期函数,我如何将其分解为日期、月、年、小时、分钟、秒。 我是这样尝试的请告诉我可行的解决方案 我的尝试: $string="2012-1-12 51:00:00.5"; $pieces = explode(" ", $date); $pieces = explode("-", $date); $pieces = explode(":", $date); 输出: Array ( [0] =&g

我有一根绳子

$string="2012-1-12 51:00:00.5";
如果不使用日期函数,我如何将其分解为日期、月、年、小时、分钟、秒。 我是这样尝试的请告诉我可行的解决方案

我的尝试:

  $string="2012-1-12 51:00:00.5";
$pieces = explode(" ", $date);
$pieces = explode("-", $date);
$pieces = explode(":", $date);
输出:

Array
(
    [0] => Array
        (
            [0] => 2012-1-12
            [1] => 51:00:00.5
        )

    [1] => Array
        (
            [0] => 2012
            [1] => 1
            [2] => 12 51:00:00.5
        )

    [2] => Array
        (
            [0] => 2012-1-12 51
            [1] => 00
            [2] => 00.5
        )

)

您可以使用
preg_split
,因为您需要对3个参数进行分解,这可以-

$string="2012-1-12 51:00:00.5";
$pieces = preg_split("/[-: ]/", $string);
var_dump($pieces);
/*
array
  0 => string '2012' (length=4)
  1 => string '1' (length=1)
  2 => string '12' (length=2)
  3 => string '51' (length=2)
  4 => string '00' (length=2)
  5 => string '00.5' (length=4)
*/

您可以使用
preg_split
,因为您需要对3个参数进行分解,这可以-

$string="2012-1-12 51:00:00.5";
$pieces = preg_split("/[-: ]/", $string);
var_dump($pieces);
/*
array
  0 => string '2012' (length=4)
  1 => string '1' (length=1)
  2 => string '12' (length=2)
  3 => string '51' (length=2)
  4 => string '00' (length=2)
  5 => string '00.5' (length=4)
*/

您可以使用
preg_split
,因为您需要对3个参数进行分解,这可以-

$string="2012-1-12 51:00:00.5";
$pieces = preg_split("/[-: ]/", $string);
var_dump($pieces);
/*
array
  0 => string '2012' (length=4)
  1 => string '1' (length=1)
  2 => string '12' (length=2)
  3 => string '51' (length=2)
  4 => string '00' (length=2)
  5 => string '00.5' (length=4)
*/

您可以使用
preg_split
,因为您需要对3个参数进行分解,这可以-

$string="2012-1-12 51:00:00.5";
$pieces = preg_split("/[-: ]/", $string);
var_dump($pieces);
/*
array
  0 => string '2012' (length=4)
  1 => string '1' (length=1)
  2 => string '12' (length=2)
  3 => string '51' (length=2)
  4 => string '00' (length=2)
  5 => string '00.5' (length=4)
*/

如您的查询评论中所述,需要进行三次分解:

list($date, $time) = explode(" ", $string);
list($year, $month, $day) = explode("-", $date);
list($hours, $mins, $sec) = explode(":", $time);

/*print the values of $year, $date and  so on*/

希望这有帮助。当然,假设应用程序中的所有日期-时间值都是上述格式,这一点就行了。

如查询注释中所述,需要进行三次分解:

list($date, $time) = explode(" ", $string);
list($year, $month, $day) = explode("-", $date);
list($hours, $mins, $sec) = explode(":", $time);

/*print the values of $year, $date and  so on*/

希望这有帮助。当然,假设应用程序中的所有日期-时间值都是上述格式,这一点就行了。

如查询注释中所述,需要进行三次分解:

list($date, $time) = explode(" ", $string);
list($year, $month, $day) = explode("-", $date);
list($hours, $mins, $sec) = explode(":", $time);

/*print the values of $year, $date and  so on*/

希望这有帮助。当然,假设应用程序中的所有日期-时间值都是上述格式,这一点就行了。

如查询注释中所述,需要进行三次分解:

list($date, $time) = explode(" ", $string);
list($year, $month, $day) = explode("-", $date);
list($hours, $mins, $sec) = explode(":", $time);

/*print the values of $year, $date and  so on*/

希望这有帮助。当然,如果应用程序中的所有日期-时间值都是上述格式,则此操作将起作用。

总共需要3次分解。。第一次分解应该是空格分隔符…@user1844933:您是对的,但是输出是更新的我的问题检查。总共需要3次分解。。第一次分解应该是空格分隔符…@user1844933:您是对的,但是输出是更新的我的问题检查。总共需要3次分解。。第一次分解应该是空格分隔符…@user1844933:您是对的,但是输出是更新的我的问题检查。总共需要3次分解。。第一次分解应该是空格分隔符…@user1844933:你是对的,但是输出是更新了我的问题检查。谢谢@prahalad deshpandethance@prahalad deshpandethance@prahalad deshpandethance@prahalad deshpandethance@prahalad deshpande