2016-05-04 76 views
-1

試圖使用moment.js格式化日期。Moment.js錯誤-cannot查找方法時刻

我已經將庫的來源包括到頭文件中。日期對象從mysql數據庫中檢索但是當我嘗試格式化日期對象時,出現一個表示moment()不是已知方法的錯誤。庫位於腳本文件夾中。

這是頭文件

<?PHP 
 
include_once 'includes/db_connect.php'; 
 
include_once 'includes/menu.php'; 
 
?> 
 

 
<!DOCTYPE html> 
 

 
<html> 
 
<head> 
 
<title>Title of the document</title> 
 
<meta charset="UTF-8"> 
 
    
 
    <script src="scripts/moment.min.js" type="text/javascript"></script> 
 
    <script src="scripts/datetime-moment.js" type="text/javascript"></script> 
 
</head> 
 
<body> 
 

 
<header> 
 

 
    </header> 
 

 
<div class="nav"> 
 

 
<?PHP menuIterms($dbh); 
 
     \t ?> \t \t \t 
 
</div>

這是從頁面的主體的代碼

<?php 
 

 
$stmt = $dbh->prepare("SELECT * FROM data_centre_users "); 
 
    
 
      if($stmt->execute()){ 
 
       // output data of each row 
 
       while($rows = $stmt->fetch(PDO::FETCH_ASSOC)){ ?> 
 
        <tbody> 
 
         <tr> 
 
         <td class="center"><?php echo $rows['id']; ?></td> 
 
         <td class="center"><?php echo $rows['first_name']." ".$rows['last_name']; ?></td> 
 
         <td class="center"><?php echo $rows['department']; ?></td> 
 
         <td class="center"><?php echo $rows['unit']; ?></td> 
 
         <td class="center"><?php echo $rows['purpose']; ?></td> 
 
         <td class="center" > 
 
          <input name="booking_time" type="datetime-local" id="booking_time" value="<?php echo moment($rows['booking_time']).format('MM/DD/YYYY'); ?>" size="15"> 
 
         </td> 
 
    <?PHP      } 
 
      } ?> 
 
     

這是電子顯示的錯誤 enter image description here

回答

1

你已經包括了moment.js這是一個JavaScript庫。你不能這樣稱呼它。按照以下內容嘗試使用php內置日期和時間戳,並將其替換爲您的代碼。

echo date('m/d/Y', strtotime($rows['booking_time']));