03/01/2025JS
Différents formats de date
hh:mm (18:10)
const getHoursMinutes = (date) => {
const hour = new Date(date).getHours();
const minutes = new Date(date).getMinutes();
return hour < 10
? minutes < 10
? `0${hour}:0${minutes}`
: `0${hour}:${minutes}`
: minutes < 10
? `${hour}:0${minutes}`
: `${hour}:${minutes}`;
};
dd MM (7 Juil.)
const getDayMonth = (date) => {
return new Date(date).toLocaleDateString('fr-FR', {
month: 'short',
day: 'numeric',
});
};
dd/mm/yy (07/07/2022)
const getDate = (date) => {
return new Date(date).toLocaleDateString('fr-FR', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
});
};
dd/mm/yy, hh:mm:ss (29/11/2022, 09:30:49)
const getDateTime = () => {
return new Intl.DateTimeFormat('fr-FR', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
}).format(new Date());
};
0