Javascript 如何在angular对象中使用日期管道并将其格式化为节点的JSON?

Javascript 如何在angular对象中使用日期管道并将其格式化为节点的JSON?,javascript,node.js,angular,typescript,Javascript,Node.js,Angular,Typescript,我试图将当前日期作为对象属性,并将其转换为节点后端的Json。我也不知道节点中的date属性是否会从前端捕获实例 我有四分之二的角 const newCustomer = { firstName: this.firstName; lastName: this.lastName; date: number = Date.now(); } 我的路由器.post在节点中 router.post('/customers', (req,res,next) =>{ let new

我试图将当前日期作为对象属性,并将其转换为节点后端的Json。我也不知道节点中的date属性是否会从前端捕获实例

我有四分之二的角

const newCustomer = {
   firstName: this.firstName;
   lastName: this.lastName;
   date: number = Date.now();
}
我的路由器.post在节点中

router.post('/customers', (req,res,next) =>{

let newCustomer = new Customer({

    firstName: req.body.firstName,
    lastName: req.body.lastName,
    date: Date.now()


});

newCustomer.save(function(err, Customer){

    if (err){

        res.json({msg: 'Failed to add contact'});

    }else{

        res.json({msg: 'Customer added to waitlist'});

    }
});
我的客户模型/模式

const customerSchema = new Schema({

date: new Date();

firstName: {
    type: String,
    //required means there has to be a name
    required: true
},

lastName: {
    type: String,
    required: true
}


});

由于您将日期对象作为JSON传递到后端,因此应该序列化该对象,但您可以在节点应用程序中创建一个新的日期对象来解析序列化的日期对象。参考号

var backendDate = new Date(jsonSerializedDate);