关于 mongodb:Mongoose 日期模式在前端返回错误的日期格式(AngularJS) | 珊瑚贝

Mongoose date schema returns wrong format for date on front end (AngularJS)


我正在使用 MongoDB、Mongoose.js、Express.js、npm 和 AngularJS 编写一个 Web 应用程序。

我有一个带有日期范围输入字段的表单,数据被发送到服务器,然后通过使用返回到 Angular:

1
2
    <td> Date Range: </td>
    <td> {{post.FromDate}} – {{post.ToDate}} </td>

我的 Mongoose 架构如下所示:

1
2
3
4
5
6
     var mongoose = require(‘mongoose’);

     var postSchema = new mongoose.Schema({
        FromDate: Date,
        ToDate: Date,
     });

但是,这会以以下格式显示日期供用户查看:

2015-07-09T07:00:00.000Z – 2015-07-16T07:00:00.000Z

有更简洁的格式吗?如何获得类似:YYYY/MM/DD – YYYY/MM/DD?

  • 更改您在 mongodb 中存储日期的方式,或者在退出时使用 javascript 日期函数解析为适合您的 UI w3schools.com/jsref/jsref_obj_date.asp 的格式


您可以在视图中使用angular日期过滤器

{{post.FromDate |日期:yyyy/MM/dd}} – {{post.ToDate |日期:yyyy/MM/dd}}


来源:https://www.codenong.com/31351697/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9303.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?