2012-07-04 285 views
8

我的日期格式爲Jun 26, '12
strtotime()轉換正確的日期字符串,並且此字符串導致空白輸出。 這可以解決,但我只能想到醜陋的做法。將日期轉換爲UNIX時間戳

將日期格式優雅地轉換爲UNIX時間戳的任何想法?

+1

您是否僅僅使用php的解決方案? – hroptatyr

+0

你使用哪種編程語言?同時告訴我們你到目前爲止嘗試過什麼?發佈SSCCE(http://sscce.org)。 –

+0

@hroptatyr Yes..only php – user1425322

回答

16

這個怎麼樣strtotime('Jun 26,12');

+0

Blank Output ... – user1425322

+0

works ...對以上評論抱歉 – user1425322

+0

我能夠通過爆炸,然後直接使用strtotime()...使用這個..很多 – user1425322

0

恩,s/'/20/g'?跟着strtotime()

+0

更具體請 – user1425322

+1

有趣的是,這與同意的答案是同構的。 –

0

也許這樣?

$string = 'April 26,\'12'; 
echo strtotime(preg_replace('/(\w+) (\d+),\'(\d+)/i', '$2 $1 20$3', $string)); 

基於例如從php.net

+0

我想如果它被更多的空格或製表符分隔,你可以試試這個:echo strtotime(preg_replace('/(\ w +)[\ s] {1,}(\ d +),[\ s] {0,} \'[\ s] {1,}(\ d +)/ i','$ 2 $ 1 20 $ 3',$ string)); – Stano

相關問題