ionic: ปัญหา Date

Javascript date is invalid on iOS

Your date string is not in a format specified to work with new Date. The only format in the spec is a simplified version of ISO-8601, but that was only added in ES5 and so support may be touch and go. Your string isn’t in that format, but it’s really close.

Note that there was an error in the ES5 specification which was corrected in ES2015 (ES6):

พยายามหลีกเลี่ยงการกำหนดค่าให้กับตัวแปร Date โดยตรง
เช่น กำหนดให้เป็นวันที่ปัจจุบันก่อน แล้วค่อยกำหนดวัน กำหนเดือน ดังตัวอย่างนี้

[code]
this.date = new Date();
this.date.setDate(2); // 2
this.date.setMonth(5); // june
[/code]

*โดย Jan น่าจะเริ่ม่ที่ 0

อันนี้น่าจะแก้ปัญหาได้นะ น่าจะ work!!

[code]
var firstDayThisMonth = new Date(this.date.getFullYear(), this.date.getMonth(), 1).getDay();
[/code]

เป็นการกำหนดให้เป็นวันที่ 1 ของเดือนปี ที่กำหนด

แต่ถ้าต้องการแค่เปรียบเทียบว่าวันที่ตรงกันมั๊ย กำหนดให้เป็น string แทน เช่น

[code]
let thisDate = this.date.getFullYear() + "-" + month + "-" + date;
[/code]