0

I want to transform a script in node.js that displays a date in english format

April 29

to a french format

29 Avril

From extracted data :

2019-04-16T13:00:00+02:00

I know that extracted data is already split (function convertParametersDate) and I have to modify it but I can't do it well

Here is the extract of my code :

[...]
const timeZone = 'Europe/Kaliningrad';  
const timeZoneOffset = '+02:00';  

[...]

function convertParametersDate(date, time){
  return new Date(Date.parse(date.split('T')[0] + 'T' + time.split('T')[1].split('+')[0] + timeZoneOffset));
}

function addHours(dateObj, hoursToAdd){
  return new Date(new Date(dateObj).setHours(dateObj.getHours() + hoursToAdd));
}

function getLocaleTimeString(dateObj){
  return dateObj.toLocaleTimeString('fr-FR', { hour: 'numeric', hour12: false, timeZone: timeZone });
}

function getLocaleDateString(dateObj){
  return dateObj.toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', timeZone: timeZone });
}
Fab_
  • 13
  • 1
  • 6

1 Answers1

1

You can use Date.toLocaleString():

const date = new Date('2019-04-16T13:00:00+02:00');
date.toLocaleString('fr-FR', { month: 'long', day: 'numeric' })

const date = new Date('2019-04-16T13:00:00+02:00');
console.log(
date.toLocaleString('fr-FR', { month: 'long', day: 'numeric' })
);
Fraction
  • 11,668
  • 5
  • 28
  • 48