最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between toLocaleString, toLocaleDateString, and toLocaleTimeString? - Stack Overflow

programmeradmin0浏览0评论

Trying to read the documentation, but can't seem to find what, if anything, is the difference between these. They all seem to accept the same parameters and locales, and they seem to return the same values.

Are they just aliases of the same function? Or is there actually a difference between them?

const locale = 'no-nb'
const options = {
  day: '2-digit', month: 'long',
  hour: '2-digit', minute: '2-digit'
}

new Date().toLocaleString(locale, options)
"18. mai, 15"

new Date().toLocaleDateString(locale, options)
"18. mai, 15"

new Date().toLocaleTimeString(locale, options)
"18. mai, 15"

Trying to read the documentation, but can't seem to find what, if anything, is the difference between these. They all seem to accept the same parameters and locales, and they seem to return the same values.

Are they just aliases of the same function? Or is there actually a difference between them?

const locale = 'no-nb'
const options = {
  day: '2-digit', month: 'long',
  hour: '2-digit', minute: '2-digit'
}

new Date().toLocaleString(locale, options)
"18. mai, 15"

new Date().toLocaleDateString(locale, options)
"18. mai, 15"

new Date().toLocaleTimeString(locale, options)
"18. mai, 15"
Share Improve this question asked May 18, 2020 at 13:17 SvishSvish 158k180 gold badges476 silver badges629 bronze badges 3
  • I'd guess it's the same code except they have different default option values. – Rup Commented May 18, 2020 at 13:24
  • 3 Documentation is a great thing. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… – epascarello Commented May 18, 2020 at 13:29
  • 1 @epascarello It would be more helpful if you told us which parts of your documentation link are related to the question at hand

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论