简体   繁体   English

如何在javascript中使用php以d/M/Y格式显示日期

[英]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.

相关问题 用(d MY)格式比较javascript中的日期 - Compare date in javascript with (d M Y) format 如何使用javascript date.js库以d / m / y格式获取日期? - How to get date in d/m/y format using javascript date.js library? 新的Date(date).getTime(); 以d / m / y格式读取时间 - new Date(date).getTime(); to read time in d/m/y format 将(例如)Ymd 字符串从 PHP 转换为 JS 中的等效日期格式 - Convert a string of (for example) Y-m-d from PHP to the equivalent date format in JS 使用JavaScript将Javascript日期对象转换为php Ymd字符串 - Convert Javascript date object to php Y-m-d string using javascript 获取日期为“ 2015-08-04” {“ YMD”}格式。 如何将指定的日期格式更改为UTC格式? - Getting date in '2015-08-04'{“Y-M-D”} format. How to change the specified date format into UTC format? 如何将Rails%d /%m /%Y日期格式字符串转换为dd / mm / yyyy? - How to convert Rails %d/%m/%Y date format string to dd/mm/yyyy? 工具提示中的NVD3输出日期格式为%d /%m /%y,x轴日期为%d /%m - NVD3 output date format in tooltip as %d/%m/%y and x-axis date as %d/%m 如何在 Javascript 中将 Epoch 中的日期转换为“Ymd H:i:s”? - How can I convert a date in Epoch to "Y-m-d H:i:s" in Javascript? 日期差异,已通过多少HDMY - Date Difference, how many H D M Y have passed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM