Hi All,
How to get the time only from the api response
'Fri, 10-Mar-2023 15:31:14', 'Thu, 09-Mar-2023 15:30:33', ==>i get the response from api in this date time format how to get the time only.
Hi All,
How to get the time only from the api response
'Fri, 10-Mar-2023 15:31:14', 'Thu, 09-Mar-2023 15:30:33', ==>i get the response from api in this date time format how to get the time only.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 13, 2023, 2:27 AM EDT
Hello Vinoth,
Try below:
// assuming the API response is stored in a variable called apiResponse const apiResponse = 'Fri, 10-Mar-2023 15:31:14'; // split the API response string into date and time components const dateTimeArr = apiResponse.split(' '); // extract the time component from the resulting array const timeStr = dateTimeArr[1]; console.log(timeStr); // output: '15:31:14'Thanks
Naimish Makwana
Amit MohantyRank #112 · 20K reputationPosted Mar 13, 2023, 2:12 AM EDT
Try this
const dateTimeStrings = "your api response"; const times = dateTimeStrings.map(dateTimeString => { const dateTime = new Date(dateTimeString); return dateTime.toLocaleTimeString(); }); console.log(times);Jignesh KumarRank #91 · 22.9K reputationPosted Mar 13, 2023, 2:17 AM EDT
Hello Vinoth,
You can try this one, where you are getting reponse need to use this one, Create function and call where you want to use it
const d = new Date('Fri, 10-Mar-2023 15:31:14') // Parses a Date console.log(d.getHours()); // gets the hours in the timezone of the browser. console.log(d.getUTCHours()); // gets the hours in UTC timezone. console.log(d.getMinutes()); // gets the minutes in the timezone of the browser. console.log(d.getUTCMinutes()); // gets the minutes in UTC timezone. console.log(d.getHours() + ':' + d.getMinutes()); console.log(d.getUTCHours() + ':' + d.getUTCMinutes());