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

242
Views
Change date format in a json file

I have a JSON file with multiple entries similar to the one below

[
 {
  "timestamp": "7/8/2021",
  "parent": "/develop-life-skills/",
  "name": "Markus",
  "comment": "Lorem ipsum dola sit amet.",
  "isAuthor": false
  }
]

Would anyone advise me on how to convert the timestamp from m/d/yyyy to a format of yyyy-mm-dd?

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

0

Try using the built-in toLocateDateString()...

let formattedDate = new Date(item.timestamp).toLocaleDateString('en-CA', { year: 'numeric', month: 'numeric', day: 'numeric' });
about 4 years ago · Juan Pablo Isaza Report

0

I would take that data, throw it into a script that uses JSON.parse(data) and maps over that data to update the value accordingly. Using a library like date-fns is what I'd reach for.

import {format} from 'date-fns';

const data = [
 {
  "timestamp": "7/8/2021",
  "parent": "/develop-life-skills/",
  "name": "Markus",
  "comment": "Lorem ipsum dola sit amet.",
  "isAuthor": false
  }
];

const formattedData = JSON.parse(data).map(item => {
  const itemWithNewDateFormat = {
    ...item,
    timestamp: format(new Date(item.timestamp), 'yyyy-mm-dd')
  }

  return itemWithNewDateFormat;
});

// You could then stringify with JSON.stringify(formattedData)

about 4 years ago · Juan Pablo Isaza Report

0

try this, if you use map funciton, it will create another array, this code updates existed one

var json=...your obj;

json.forEach((item) => {
  var arr = item.timestamp.split("/");
  item.timestamp = `${arr[2]}-${arr[0].padStart(2,"0")}-${arr[1].padStart(2,"0")}`;
});
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!