gpt4 book ai didi

d3.js - D3 时间格式化语言环境

转载 作者:行者123 更新时间:2023-12-01 12:30:36 29 4
gpt4 key购买 nike

是否可以从 D3 时间格式返回本地化信息?

d3.time.format('%B %Y')(new Date(d))

这总是返回 EN 值。

最佳答案

是的,这是可能的。有一个 github wiki 页面 here .

基本上你需要使用d3.locale(definition)方法。定义是这样一个对象:

{
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["$", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%m/%d/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
}

更新

The formatting of numbers, dates and currencies varies by language and locale. While the default build of D3 is intended for U.S. English, you can change the behavior of D3’s formatters by loading new locales as needed.

因此,语言环境不会自动识别,您应该自己加载所需的内容。

小例子:

var ua = d3.locale(<uk_UA definition>); //you need this object to be available everywhere this locale is required
ua.timeFormat('%B %Y'); //use this instead of d3.time.format('%B %Y')

关于d3.js - D3 时间格式化语言环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34437526/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com