- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 mySql 表,其中有一个名为 posts 的列,该列设置为 timestamp
类型,默认为 current_timestamp
。然后,我使用 php PDO 获取它的值(以及其他一些列),并 echo json_encode
整个内容。我使用 AJAX 调用来调用我的 .php 文件,现在我想格式化我收到的日期。
一些谷歌搜索导致我为其 $.datepicker
函数添加了 jQuery-UI,作为格式化数据的简单方法。由于我可能会在页面上使用其他一些 jQuery-UI 元素,因此这似乎是一个合理的解决方案。到目前为止,我还无法让它工作。
当我console.log
相关对象时,我得到这个结果“2015-06-10 13:26:54”
。
这是我的 JS 代码(您应该查看已发布的 var):
function makeArticleFeed(response) {
$('#articles-feed').empty();
if(response.length > 0) {
for(var x = 0; x<response.length; x++) {
console.log(response[x].posted);
var posted = $.datepicker.formatDate('dd m yy', new Date(response[x].posted));
$("#articles-feed").append(
'<div class="article-box"><h1><a href="#">'+response[x].title+
'</a></h1><h3><a href="#">' +response[x].author_id+
'</a> | '+ posted+
'</h3><p>'+response[x].extract+'</p></div>'
);
} //end article feed for loop
}
else {
$("#articles-feed").append('<h1>Sorry, no article found!</h1>');
}
最佳答案
这就是将字符串 Invalid Date
传递给 formatDate()
函数时得到的结果。
换句话说,response[x].posted
不是 javascript new Date
可以解析的有效日期。
如果它是来自 MySQL 的时间戳,则通常采用 2015-06-11 16:48:24
格式,并且您可以在大多数服务器端语言中获取纪元时间,例如只需将其传递给 PHP strtotime
可以工作,然后你会得到从纪元开始的秒数,并且 javascript 接受毫秒,因此你可以在服务器上或在将其传递给 new Date
之前乘以一千>.
关于javascript - jQuery UI $.datepicker.formatDate 返回 NaN NaN Nan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787615/
首先我想说的是,我知道isNaN()和 Number.isNaN()工作。我正在阅读 David Flanagan 的 The Definite Guide,他举例说明了如何检查值是否为 NaN :
在表中,对于 skips day 列,最后一行的默认值始终是单词“last”,它不是数字。现在,结果日期显示为“NaN/NaN/NaN”,有什么方法可以将其替换为 Nil 之类的东西。 非常感谢。
我正在制作一个网站,如果用户登录,则会为用户提供一定的注销时间,其中定义了注销时间,剩余时间是从注销时间 - 服务器时间获得的。 我已经通过 PHP 获得了注销时间和服务器时间,但我想动态显示剩余时间
我有以下代码,它简单地初始化一个 UIImageView 以适应 UIImage 在当前屏幕尺寸上尽可能大的比例: CGSize mainScreenSize = [appDelegate mainS
这个问题已经有答案了: Why in numpy `nan == nan` is False while nan in [nan] is True? (1 个回答) 已关闭 3 年前。 我只是觉得这有
我有动态 JQGrid,其中一列是日期列。我从包含 URL 和日期的 feed 中获取数据。 我需要为“日期列”开发列模型,使其显示日期和超链接。但不幸的是,数据显示为 NAN/NAN/NAN (这可
我已经包含了一个演示我的问题的片段。基本上处理给了我这个错误: 调用map(NaN, -3, 3, -125, 125),返回NaN(不是数字) 我理解此消息的方式是,map 函数返回 NaN,并且由
我在下面创建的过滤器适用于 Chrome,但不适用于 Firefox。我不明白为什么。 myApp.filter('dateCustom', [ '$filter', function ($fil
虽然问题的第一部分(在标题中)之前已经回答过几次(即 Why is NaN not equal to NaN? ),但我不明白为什么第二部分会以它的方式工作(受此启发问题 How to Check l
我需要在数组中找到min和max值(不考虑可能的NaN值在这个数组中)。 这只使用 double 会很容易,但是这些 FindMin 和 FindMax 函数必须使用泛型类型。 我尝试以这种方式测
我正在开发一个屏幕,其中 UIScrollView 内只有一个 UIImageView。 UIScrollView 使用户能够固定和缩放图像。我从下面的帖子中得到了帮助。它使用 Storyboard和
尽管看到了类似的答案,但我不知道这里发生了什么。我制作了一个自定义的 UIImageview,它应该在创建后立即开始动画: class HeaderAnimator: UIImageView {
我正在寻找一个 pandas 系列并用下一个数值的平均值填充 NaN,其中:average = next numerical value/(# consecutive NaNs + 1) 到目前为止,
我有一个 mySql 表,其中有一个名为 posts 的列,该列设置为 timestamp 类型,默认为 current_timestamp。然后,我使用 php PDO 获取它的值(以及其他一些列)
我想知道以下类型的 nan 之间有什么区别。除了 NAN_macro (计算结果为 -nan(ind) 而不是 nan )的视觉差异外,它们的行为似乎都相同(根据下面的示例脚本)。 我看了一些其他的答
我为我的网页做了倒计时;它在除 Mozilla 和 IE 之外的所有浏览器上都能正常工作。 我做错了什么,我该如何解决? 下面是我的代码: ***var dt = '2018-06-14 11:59
在将 Xcode 更新到 8.3 后,我在启动时开始收到此错误:由于未捕获的异常“CALayerInvalidGeometry”而终止应用程序,原因:“CALayer 位置包含 NaN:[nan na
我正在使用 jquery 自动完成 onselect 它在不同的文本字段中显示数据。我使用 format_date() 函数在 #dob 和 #anniversery 中显示格式化日期 select:
我有一个带有 json Store 和 DateField 的网格。 Firefox 运行良好,但在 Internet Explorer 8 中无法运行。 我这样定义: function conver
我有一个错误,它在启动时使应用程序崩溃。这是我得到的错误: *** Terminating app due to uncaught exception 'CALayerInvalidGeometry'
我是一名优秀的程序员,十分优秀!