Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
How to get just the day from ISO string javascript

I have an ISO date coming back from a server and before I send it to the frontend I want to convert the ISO date to something like this

2011-10-05T14:48:00.000Z

time: {
          day: 'Tue',
          hour: '11:54 AM',
          date: 'May 5, 2019'
        }

I dont want to use a bunch of regex unless I have to, I was hoping I could achieve this with just functions like .toDateString() etc... is there a toDateDayString or something like that?

Here is the snippet of the actual function sending the info back to my frontent.

Id like to be able to to this inline from a promise in .then()

allMessages = [] 

await subClient.conversations.services(convoServiceSid)
           .conversations(convo)
           .messages
           .list({limit: 20})
           .then(messages => messages.forEach(m =>
 allMessages.push({"messagesId": m.conversationSid, "time": m.dateCreated.toDateString() }) ));
//m.dateCreated is always going to be an ISO string, I want to make an object with day, hour, date if possible

res.json(allMessages)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I think you can do it like this:

const date = new Date('2011-10-05T14:48:00.000Z');
const format = {
   day: date.getDay(),
   hour: `${date.getHours()} ${date.getMinutes()}`,
   date: `${date.getMonth()} ${date.getFullYear()}`
};
about 4 years ago · Juan Pablo Isaza Report

0

You can use toLocaleDateString method

function get_time(iso_date_str) {
  const [day, month_date, year, hour] = (
    new Date(iso_date_str).toLocaleDateString('en', {
      weekday: 'short',
      hour: 'numeric',
      minute: 'numeric',
      month: 'short',
      day: 'numeric',
      year: 'numeric',
    })
    .split(/,\s?/)
  );
  return {
    day,
    hour,
    date: month_date + ', ' + year
  };
}

console.log(get_time('2011-10-05T14:48:00.000Z'));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!