Unable to call web api because not getting date in correct format to add in url
up vote
0
down vote
favorite
Whenever I am trying to call web api by using value from datepicker, it is displaying date in weird manner resulting bad request from server.
GET https://lihcode-lufthansa-open-new-v1.p.mashape.com/v1/operations/schedules/sfo/bom/1542738600000?limit=10 400 (Bad Request).
Here date is 154273860000, but I want date in 2018-11-20(yyyy-mm-dd).
and here it is my component html for date.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination">
<mat-hint align="end">Destination airport.
</mat-form-field>
and my modal class is:
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public limit: string
) {}
}
I need help, please someone help me
Thanks in advance
angular api date
add a comment |
up vote
0
down vote
favorite
Whenever I am trying to call web api by using value from datepicker, it is displaying date in weird manner resulting bad request from server.
GET https://lihcode-lufthansa-open-new-v1.p.mashape.com/v1/operations/schedules/sfo/bom/1542738600000?limit=10 400 (Bad Request).
Here date is 154273860000, but I want date in 2018-11-20(yyyy-mm-dd).
and here it is my component html for date.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination">
<mat-hint align="end">Destination airport.
</mat-form-field>
and my modal class is:
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public limit: string
) {}
}
I need help, please someone help me
Thanks in advance
angular api date
there should not be any constructor in the model class. it should be like thisexport class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.
– ashish pal
Nov 19 at 7:22
How are you adding the date in yourdate
string. Please share that code.
– Nabil Shahid
Nov 19 at 7:36
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Whenever I am trying to call web api by using value from datepicker, it is displaying date in weird manner resulting bad request from server.
GET https://lihcode-lufthansa-open-new-v1.p.mashape.com/v1/operations/schedules/sfo/bom/1542738600000?limit=10 400 (Bad Request).
Here date is 154273860000, but I want date in 2018-11-20(yyyy-mm-dd).
and here it is my component html for date.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination">
<mat-hint align="end">Destination airport.
</mat-form-field>
and my modal class is:
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public limit: string
) {}
}
I need help, please someone help me
Thanks in advance
angular api date
Whenever I am trying to call web api by using value from datepicker, it is displaying date in weird manner resulting bad request from server.
GET https://lihcode-lufthansa-open-new-v1.p.mashape.com/v1/operations/schedules/sfo/bom/1542738600000?limit=10 400 (Bad Request).
Here date is 154273860000, but I want date in 2018-11-20(yyyy-mm-dd).
and here it is my component html for date.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination">
<mat-hint align="end">Destination airport.
</mat-form-field>
and my modal class is:
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public limit: string
) {}
}
I need help, please someone help me
Thanks in advance
angular api date
angular api date
edited Nov 19 at 9:39
ganesh045
501113
501113
asked Nov 19 at 7:14
mmodalities
123
123
there should not be any constructor in the model class. it should be like thisexport class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.
– ashish pal
Nov 19 at 7:22
How are you adding the date in yourdate
string. Please share that code.
– Nabil Shahid
Nov 19 at 7:36
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18
add a comment |
there should not be any constructor in the model class. it should be like thisexport class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.
– ashish pal
Nov 19 at 7:22
How are you adding the date in yourdate
string. Please share that code.
– Nabil Shahid
Nov 19 at 7:36
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18
there should not be any constructor in the model class. it should be like this
export class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.– ashish pal
Nov 19 at 7:22
there should not be any constructor in the model class. it should be like this
export class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.– ashish pal
Nov 19 at 7:22
How are you adding the date in your
date
string. Please share that code.– Nabil Shahid
Nov 19 at 7:36
How are you adding the date in your
date
string. Please share that code.– Nabil Shahid
Nov 19 at 7:36
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Edited
Try to format the date on ngModelChange
event but you have to assign to another property (formatedDate) and get the date from formatedDate property.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination"
(ngModelChange)="formater(flightSchedule.date)"> <--- here
Add a new property formatedDate
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public formatedDate?: string, <--- here
public limit: string
) {}
}
Add a function in you class
formater(unixTime: number) {
var date = new Date(unixTime);
var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`;
this.flightSchedule.formatedDate = myDate;
}
For momentjs
formater(unixTime: number) {
const date = new Date(unixTime);
const myDate = moment(date).format('YYYY-MM-DDTHH:mm);
this.flightSchedule.formatedDate = myDate;
}
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Edited
Try to format the date on ngModelChange
event but you have to assign to another property (formatedDate) and get the date from formatedDate property.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination"
(ngModelChange)="formater(flightSchedule.date)"> <--- here
Add a new property formatedDate
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public formatedDate?: string, <--- here
public limit: string
) {}
}
Add a function in you class
formater(unixTime: number) {
var date = new Date(unixTime);
var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`;
this.flightSchedule.formatedDate = myDate;
}
For momentjs
formater(unixTime: number) {
const date = new Date(unixTime);
const myDate = moment(date).format('YYYY-MM-DDTHH:mm);
this.flightSchedule.formatedDate = myDate;
}
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
|
show 1 more comment
up vote
0
down vote
accepted
Edited
Try to format the date on ngModelChange
event but you have to assign to another property (formatedDate) and get the date from formatedDate property.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination"
(ngModelChange)="formater(flightSchedule.date)"> <--- here
Add a new property formatedDate
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public formatedDate?: string, <--- here
public limit: string
) {}
}
Add a function in you class
formater(unixTime: number) {
var date = new Date(unixTime);
var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`;
this.flightSchedule.formatedDate = myDate;
}
For momentjs
formater(unixTime: number) {
const date = new Date(unixTime);
const myDate = moment(date).format('YYYY-MM-DDTHH:mm);
this.flightSchedule.formatedDate = myDate;
}
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
|
show 1 more comment
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Edited
Try to format the date on ngModelChange
event but you have to assign to another property (formatedDate) and get the date from formatedDate property.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination"
(ngModelChange)="formater(flightSchedule.date)"> <--- here
Add a new property formatedDate
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public formatedDate?: string, <--- here
public limit: string
) {}
}
Add a function in you class
formater(unixTime: number) {
var date = new Date(unixTime);
var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`;
this.flightSchedule.formatedDate = myDate;
}
For momentjs
formater(unixTime: number) {
const date = new Date(unixTime);
const myDate = moment(date).format('YYYY-MM-DDTHH:mm);
this.flightSchedule.formatedDate = myDate;
}
Edited
Try to format the date on ngModelChange
event but you have to assign to another property (formatedDate) and get the date from formatedDate property.
<input required matInput #input maxlength="3"
name="destination" placeholder="Enter destination"
class="form-control
[(ngModel)]="flightSchedule.destination"
(ngModelChange)="formater(flightSchedule.date)"> <--- here
Add a new property formatedDate
export class FlightSchedule {
constructor(
public destination: string,
public origin: string,
public date: string,
public formatedDate?: string, <--- here
public limit: string
) {}
}
Add a function in you class
formater(unixTime: number) {
var date = new Date(unixTime);
var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`;
this.flightSchedule.formatedDate = myDate;
}
For momentjs
formater(unixTime: number) {
const date = new Date(unixTime);
const myDate = moment(date).format('YYYY-MM-DDTHH:mm);
this.flightSchedule.formatedDate = myDate;
}
edited Nov 20 at 9:24
answered Nov 19 at 7:47
Sheik Althaf
22716
22716
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
|
show 1 more comment
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
I am getting formatedDate: "NaN-NaN-NaN" error
– mmodalities
Nov 20 at 3:07
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
Sorry wrong parameter passed. Please check the Edited
– Sheik Althaf
Nov 20 at 5:25
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
It i working perfectly brother. If i want to add HH:mm, what I need to do. Please modify the code YYYY-MM-DDTHH:mm.. I want to add extra things, but I really appreciate your helps. Thanks a lot
– mmodalities
Nov 20 at 7:24
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
are you using momentjs?
– Sheik Althaf
Nov 20 at 9:08
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
Please check the updated answer
– Sheik Althaf
Nov 20 at 9:11
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369889%2funable-to-call-web-api-because-not-getting-date-in-correct-format-to-add-in-url%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
there should not be any constructor in the model class. it should be like this
export class FlightSchedule { public destination: string, public origin: string, public date: string, public limit: string }
. suggest following good code practices.– ashish pal
Nov 19 at 7:22
How are you adding the date in your
date
string. Please share that code.– Nabil Shahid
Nov 19 at 7:36
export class FormComponent implements OnInit { date = new FormControl(moment()); constructor(private dataService: LufthansaDataService) { } flightSchedule = new FlightSchedule('fra', 'fra', '2018-11-20', '10'); ngOnInit() { } onSubmit() { this.dataService.getInformation(this.flightSchedule).subscribe(data => console.log(data)); console.log(this.flightSchedule); } }
– mmodalities
Nov 19 at 12:18