Skip to content

Instantly share code, notes, and snippets.

@afr-dt
Last active June 20, 2021 21:25
Show Gist options
  • Save afr-dt/6540796cd19fe1e0e9c97556e2d73f09 to your computer and use it in GitHub Desktop.
Save afr-dt/6540796cd19fe1e0e9c97556e2d73f09 to your computer and use it in GitHub Desktop.
Date format ES6
let date = new Date('2018-06-20T15:03:22.297024');
let options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric'
};
console.log(
date.toLocaleDateString('es-MX', options),
'a las',
date.toLocaleTimeString()
);
// With function
const DateFormat = today => {
return (today = new Date().toLocaleDateString('es-MX', options));
};
const TimeFormat = time => {
return (time = new Date().toLocaleTimeString());
};
console.log(
DateFormat('2018-06-20T15:03:22.297024'),
'a las',
TimeFormat('2018-06-20T15:03:22.297024')
);
// In one function
function dateTimeFormat(params) {
date = new Date(params).toLocaleDateString('es-MX', {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric'
})
time = new Date(params).toLocaleTimeString()
return `${date}, ${time}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment