3

Using "Date.toLocaleDateString" to get the date in a given language and format, some browsers have a comma after the year.

const myDate = new Date().toLocaleString("pt-BR", {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit'
})

console.log(myDate)

Brave Version 1.48.158 Chromium: 110.0.5481.77 (Official Build) 64 bits

'09/02/2023, 10:52:42'

Chrome Version 109.0.5414.75 (Official Build) (64-bit)

'09/02/2023 10:52:32'

Firefox 109.0.1 (64-bits)

'09/02/2023 10:52:32'

Why this difference if we are setting a specific locale ?

isherwood
  • 58,414
  • 16
  • 114
  • 157
rick
  • 554
  • 6
  • 18
  • 3
    See https://stackoverflow.com/questions/49982572/how-to-remove-comma-between-date-and-time-on-tolocalestring-in-js – isherwood Feb 09 '23 at 14:08

0 Answers0