2014-09-01 61 views
2

簡單地爆炸(d.m.Y H:i)我將使用最簡單的方式從日期字符串中爆炸(日期,月份,年份,小時,分鐘),例如這一個"2014-08-30T15:30:00"。我的PHP代碼不起作用,因爲我的結果總是"01.01.1970 01:33"如何使用Php

代碼:

$day = date("d",$timestamp); 
    $month = date("m",$timestamp); 
    $year = date("Y",$timestamp); 
    $hour = date("H",$timestamp); 
    $minute = date("i",$timestamp); 
+1

變量$ timestamp是Unix時間戳嗎? – Bjoern 2014-09-01 19:10:42

+0

你的問題包含2種輸入格式。你想使用哪一個?你的第一句話談論格式不同於第二句 – 2014-09-01 19:10:55

+0

我真的不明白你的問題 - 但看看PHP函數date()(http://php.net/manual/en/function.date.php)和mktime ()(http://php.net/manual/en/function.mktime.php),也許strtotime()可能是一個好主意。 – tillinberlin 2014-09-01 19:13:08

回答

4

使用strtotime(string)功能,例如date('d', strtotime('2014-08-30'))

+0

謝謝,它使用'strtotime();' – R2D2 2014-09-01 19:15:40

6

直接從PHP的文檔:link

<?php 
print_r(date_parse("2006-12-12 10:00:00.5")); 
?> 

這會給你的日期的不同部分的數組,如你所要求的(「最簡單的爆炸方式」)。