简体   繁体   English

Moment.js 错误 - 无法找到方法 moment

[英]Moment.js Error -cannot Find method moment

trying to use moment.js to format date.尝试使用 moment.js 来格式化日期。

I have included the source of the library to the header file.The date object is retrieved from mysql database But when I try to format the date object I get an error that says moment() is not a known method.The library is in the scripts folder.我已将库的源包含在头文件中。日期对象是从 mysql 数据库中检索的但是当我尝试格式化日期对象时,我收到一个错误,指出 moment() 不是已知方法。库位于脚本文件夹。

This is the header file这是头文件

 <?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); ?> </div>

this is the code from the body of page这是页面正文中的代码

 <?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 } } ?>

This is the error displayed这是显示的错误在此处输入图片说明

You have included moment.js which is a javascript library.您已经包含了 moment.js,它是一个 javascript 库。 You can not call it like this.你不能这样称呼它。 Try php built-in date and strtotime as follow and replace it with your code.按如下方式尝试 php 内置日期和 strtotime 并将其替换为您的代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM