我试图检索created_at时间
但它会渲染当前时间。这不是我想要的。
我将laravel 5.5与moment.js
结合使用 <p> <% post.created_at | phpDate : "human" %></p>
main.js
app.filter('phpDate', function() {
// A filter declaration should return an anonymous function.
// The first argument is the input passed to the filter
// Any additional arguments are paramaters passed AFTER the filter name
return function(input, format) {
// Create an instance of Moment. Use both the
// date value and timezone information PHP sent
var date = moment.tz(input.date, input.timezone);
if (format == "human") {
// Special case for formatting. If user asks for "human" format
// return a value like "13 minutes ago" or "2 weeks ago" etc.
return moment().subtract(1, 'days').calendar();
} else {
// Covert the moment to a string using the passed format
// If nothing is passed, uses default JavaScript date format
return moment().format('lll');
}
};
});
答案 0 :(得分:0)
在本网站上一位备受尊敬的用户的帮助下,我们能够修复它,只需要在瞬间完成时添加输入。
app.filter('phpDate', function() {
return function(input, format) {
if (format == "human") {
// add input then it works
return moment(input).subtract(1, 'days').calendar();
} else {
return moment().format('lll');
}
};
});