Last active
June 20, 2021 21:25
-
-
Save afr-dt/6540796cd19fe1e0e9c97556e2d73f09 to your computer and use it in GitHub Desktop.
Date format ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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