2010-06-09 17 views

risposta

12
<?php 
$jsDateTS = strtotime($jsDate); 
if ($jsDateTS !== false) 
date('Y-m-d', $jsDateTS); 
else 
// .. date format invalid 
+0

Grazie per le informazioni – abhis

+1

Nizza, perché si sta verificando anche il formato della data non valida. – kta

2

entrambi i casi è possibile inviare la data di javascript per php tramite query string:

var mydate = encodeURIComponent('Wed Jun 09 2010'); 
document.location.href = 'page.php?date=' + mydate; 

PHP

echo date('Y-m-d', strtotime(urldecode($_GET['date']))); 
.210

o attraverso un campo nascosto:

echo date('Y-m-d', strtotime(urldecode($_POST['date']))); 
+0

grazie per la vostra risposta – abhis

+0

@Ajith: siete i benvenuti – Sarfraz

6

O con DateTime:

$date = new DateTime('Wed Jun 09 2010'); 
echo $date->format('Y-m-d'); 

Il formato della data è possibile input per strtotime(), DateTime e date_create() sono explained in the PHP manual. Se avete bisogno di più controllo sul formato di input e hanno PHP5.3, è possibile utilizzare:

$date = DateTime::createFromFormat('D M m Y', 'Wed Jun 09 2010'); 
echo $date->format('Y-m-d'); 
Problemi correlati