js date tolocalestring code example

Example 1: js date now format

new Date().toJSON()
// "2021-01-12T01:06:54.747Z"

Example 2: m06 javascript tolocalestring returning for june

const d = new Date('2010-08-05')
const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)

console.log(`${da}-${mo}-${ye}`)

Example 3: js date enlever jour

let date = '20/10/2010'; // chaine
 let dateArray = date.split('/');// tableau jour, mois, année
 let dateObject = new Date(parseInt(dateArray[2]), parseInt(dateArray[1]) - 1, parseInt(dateArray[0])); // on créer notre objet date 
 
 console.log(dateObject.getDate());
 console.log(dateObject.getDate() - 10);

Example 4: toLocaleDateString() options

new Date("1983-March-25").toLocaleDateString('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit' })
'03/25/1983'

Example 5: toLocalString

Data.prototype.toLocaleString()

Tags:

Java Example