【日期时间星期实现多语言转化】同时发现 d3.timeFormat("%Y-%m-%d")(new Date(toDate.getTime() - i * 24 * 3600 * 1000));
在不需要语言切换的时候可以直接对中国标准时间进行转化,默认英文。
const WEEKDAYSABBR=[
{
"en": "Sun",
"zh": "星期日",
},
{
"en": "Mon",
"zh": "星期一",
},
{
"en": "Tue",
"zh": "星期二",
},
{
"en": "Wed",
"zh": "星期三",},
{
"en": "Thu",
"zh": "星期四",
},
{
"en": "Fri",
"zh": "星期五",
},
{
"en": "Sat",
"zh": "星期六",
},
];
const MONTHS = [
{
"en": "Jan",
"zh": "一月",
},
{
"en": "Feb",
"zh": "二月",
},
{
"en": "Mar",
"zh": "三月",
},
{
"en": "Apr",
"zh": "四月",
},
{
"en": "May",
"zh": "五月",
},
{
"en": "Jun",
"zh": "六月",
},
{
"en": "Jul",
"zh": "七月",
},
{
"en": "Aug",
"zh": "八月",
},
{
"en": "Sep",
"zh": "九月",
},
{
"en": "Oct",
"zh": "十月",
},
{
"en": "Nov",
"zh": "十一月",
},
{
"en": "Dec",
"zh": "十二月",
}
];
var lang;
!function () {
lang = navigator.language || navigator.userLanguage;
//常规浏览器语言和IE浏览器
lang = lang.substr(0, 2);
//截取lang前2位字符
}();
//星期
logbook.getWeekdayAbbr = function (index, lang) {
return WEEKDAYSABBR[index][lang];
};
// 月份
logbook.getMonthName = function (index, lang) {
return MONTHS[index][lang];
}// 格式化日期 dayOfWeek
logbook.formatLogDate = function (date, lang) {
let dateWeeks=logbook.getWeekdayAbbr(date.getDay(), lang);
return dateWeeks;
//return `${logbook.getWeekday(date.getDay(), lang)}`;
}// 格式化日期 month day
logbook.formatLogMonth = function (date, lang) {
return `${logbook.getMonthName(date.getMonth(), lang)}, ${date.getDate()}`;
}
function(d) { return logbook.formatLogMonth(new Date(d.date), lang) }
推荐阅读
- 前端|面试官(谈谈Vue和React的区别())
- react|高德地图的使用及自定义图标
- React|【React Native开发】React Native控件之RefreshControl组件详解(21)
- React|React Native开源项目-嘎嘎商城客户端(持续更新中)
- 工作与生活|2016总结,真正新的里程碑和新起点
- React|【React Native开发】React Native应用设备运行(Running)以及调试(Debugging)(3)
- React|【React Native开发】React Native控件之ListView组件讲解以及最齐全实例(19)
- React|React Native控件之PullToRefreshViewAndroid下拉刷新组件讲解(20)
- React|【React Native开发】React Native控件之Text组件讲解(9)
- react学习之旅|react+antd-mobile之项目构建+基础配置