angular4中日期格式的用法
dateTime: Date; this.dataTime = new Date(); // 获取当前日期 // Wed Apr 18 2018 10:54:47 GMT+0800 (中国标准时间)
欢迎加入前端交流群交流知识&&获取视频资料:749539640
所有date中所有的tostring的方法.
console.log('orderdate:', this.OrderDate); console.log('toISOString:', this.OrderDate.toISOString()); console.log('toDateString:', this.OrderDate.toDateString()); console.log('toUTCString:', this.OrderDate.toUTCString()); console.log('toJSON:', this.OrderDate.toJSON()); console.log('toLocaleDateString:', this.OrderDate.toLocaleDateString()); console.log('toLocaleString:', this.OrderDate.toLocaleString()); console.log('toLocaleTimeString:', this.OrderDate.toLocaleTimeString()); console.log('toString:', this.OrderDate.toString()); console.log('toTimeString:', this.OrderDate.toTimeString()); // 输出结果: // toISOString: 2017-12-07T16:33:01.843Z // toDateString: Fri Dec 08 2017 // toUTCString: Thu, 07 Dec 2017 16:33:01 GMT // toJSON: 2017-12-07T16:33:01.843Z // toLocaleDateString: 2017/12/8 // toLocaleString: 2017/12/8 上午12:33:01 // toLocaleTimeString: 上午12:33:01 // toString: Fri Dec 08 2017 00:33:01 GMT+0800 (中国标准时间) // toTimeString: 00:33:01 GMT+0800 (中国标准时间)
日期前台展现的用法:
前台html页面日期格式化: {{ dateTime | date:'yyyy-MM-dd HH:mm:ss'}} {{ dateTime | date:'medium' }} {{ dateTime | date:'short' }} {{ dateTime | date:'fullDate' }} {{ dateTime | date:'longDate' }} {{ dateTime | date:'mediumDate' }} {{ dateTime | date:'shortDate' }} {{ dateTime | date:'mediumTime' }} {{ dateTime | date:'shortTime' }}