I want to declare the date in the below code in the format of (yyyy mm dd hh mm ss)
.
postData(data) {
let headers = new HttpHeaders();
headers.append('Content-Type','application/json');
var pingData = {
date: new Date(year, month, day, hours, minutes, seconds, milliseconds)
}
}
When I declare it as shown in the above a code, I'm getting the error as
Cannot find name 'year'. Cannot find name 'month'.....
I want the date
variable to be string
type. So, how can I get the date as I mentioned in the above format?
Try This Maybe Helpfull for you
in AppModulePage
import {DatePipe} from '@angular/common';
providers: [DatePipe]
in demo.component.ts
import { DatePipe } from '@angular/common';
.
.
constructor(private datePipe: DatePipe) {}
ngOnInit() {
var date = new Date();
console.log(this.datePipe.transform(date,"yyyy mm dd hh mm ss"));
}
使用这种格式将可以工作var d = new Date(2018, 11, 24, 10, 33, 30, 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.