2014-03-24 48 views
0

所以我有一個用於創建計劃日期的表單。 Title,Subject,bla bla ... 但是,我有一個jQuery Date選取器,它可以讓用戶從日曆中選擇一個日期。 jQuery日期選擇器僅適用於人類日期格式 我想將它們存儲在UNIX TIME中。 所以我有這個日曆,爲年,月,日... 然後我有一個標準的下降時間,1:00 PM,1:30 PM等...結合時間/日期數組轉換爲UNIX時間

post print_r $ _ POST);看起來像這樣,

[time] => Array 
    (
     [0] => 5:00 PM 
     [1] => 1:00 PM 
     [2] => 8:00 PM 
    ) 

[date] => Array 
    (
     [0] => 2014-05-08 
     [1] => 2014-04-04 
     [2] => 2014-03-28 
    ) 

我發現strtotime();用於將人類時間/日期轉換爲UNIX時間,但是... 如何從時間和日期中獲取數組[0]並組合成字符串。 可能只有1個日期或8個日期?

回答

0

您可以通過POST數據迭代,並結合時代:

foreach($_POST['date'] as $i => $date) { 
    $timestamp = strtotime($date.' '.$_POST['time'][$i]); 
} 
+0

謝謝。我不認爲這很簡單。 – user1840958

0
$count = count($_POST['date']); // assuming both date and time have same amount of values 

for ($i = 0; $i < $count; $i++) { 
    $time = strtotime($_POST['date'][$i] . ' ' . $_POST['time'][$i]); 
    // do what you want with the time here 
    // Example: put all timestamps in an array. 
    $timestamps[] = $time; 
}