Shubham Ghormade
Shubham Ghormade

Reputation: 197

Convert time hh:mm:ss into GMT time format in Angular 2

Input:-

time: 21:00:00

Output Should Be:-

time: Wed Dec 20 2017 21:00:00 GMT+0530 (IST)

OR

time: 2017-12-20 21:00:00

Upvotes: 2

Views: 1150

Answers (1)

Anshul
Anshul

Reputation: 395

Your input is : 21:00:00

Split your input by ':' using JS code below:

let timeArr = "21:00:00".split(':');

then, use new date function to add date to the time i.e,

let newDateTime = new Date().setHours(timeArr[0], timeArr[1],0,0);

then you can convert your time to,

let finalDate = new Date(newDateTime);

and you will get the finalDate = Wed Dec 20 2017 21:00:00 GMT+0530 (IST)

Upvotes: 2

Related Questions