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










share|improve this question
























  • 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

















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










share|improve this question
























  • 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















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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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




















  • 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


















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














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;
}





share|improve this answer























  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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;
}





share|improve this answer























  • 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















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;
}





share|improve this answer























  • 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













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;
}





share|improve this answer














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;
}






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin