Issue
am follow the guide from How to convert date into this 'yyyy-MM-dd' format in angular 2 and my return result = 'null' . can pls advise where is my mistake?
mydate: string ;
date: Date;
postObj={
unitno:'',
trackno:'',
date: new Date();
};
addparcel() {
this.mydate = this.datepipe.transform(this.date, 'yyyy-MM-dd');
console.log(this.postObj.unitno)
console.log(this.postObj.trackno)
console.log(this.mydate);
}
Solution
I recommend checking out the angular documentation for datepipe here:
https://angular.io/api/common/DatePipe
TL;DR
this.mydate = this.datepipe.transform(this.date, 'yyyy-MM-dd');
is wrong, it should be something like :
this.mydate = this.datepipe.transform(this.date, 'medium');
Now in your case I assume you want to convert it to Mysql timestamp, to do that I did this:
this.dte = new Date();
let aux = this.dte.getFullYear() + "-" + ("0" + (this.dte.getMonth() + 1)).slice(-2) + "-" + ("0" + this.dte.getDate()).slice(-2) + " " + this.dte.getHours() + ":" + this.dte.getMinutes() + ":" + this.dte.getSeconds();
I know it looks long, but it works 100%
Answered By - Haythem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.