[英]how to use php in javascript for displaying date in d/M/Y format
I have this code which is supposed to retrieve date in d/M/Y format.我有这个代码,它应该以 d/M/Y 格式检索日期。 But it does not display anything.
但它不显示任何内容。 I am retrieving the value from table using jQuery and AJAX.
我正在使用 jQuery 和 AJAX 从表中检索值。 Can you tel me the code to convert date in d/M/Y format in JavaScript
你能告诉我在 JavaScript 中将日期转换为 d/M/Y 格式的代码吗
{
"render" : function(data,type,row) {
var d=<?php date('d/M/Y', strtotime(row['date_of_birth']));?>
return d;
}
},
Given that you don't say anything about the dateformat you are trying to create the date from, Im assuming its the standard from MySQL
( YYYY-mm-dd H:i:s
) because you are using row as a variable.鉴于您没有说明您尝试从中创建日期的日期格式,我假设它是
MySQL
的标准( YYYY-mm-dd H:i:s
),因为您使用 row 作为变量。
This aside, you have a couple of issues with your code.除此之外,您的代码有几个问题。 First of,
row
is missing the variable declaration.首先,
row
缺少变量声明。 It shoud be $row
它应该是
$row
Secondly, the <?php ?>
should be wrapped inside ''
.其次,
<?php ?>
应该包裹在''
。 If you don't do this, you will get a syntax error with your javascript.如果您不这样做,您的 javascript 将出现语法错误。
Third, you need to echo the date.第三,您需要回显日期。 Thus, ending up with a code like this:
因此,以这样的代码结束:
{
"render" : function(data,type,row) {
var d='<?php echo date('d/M/Y', strtotime($row['date_of_birth']));?>';
return d;
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.