d3 日期格式本地化

var locale = d3.timeFormatLocale({
    dateTime: "%a %b %e %X %Y",
    date: "%Y/%-m/%-d",
    time: "%H:%M:%S",
    periods: ["上午", "下午"],
    days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
    shortDays: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
    months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    shortMonths: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
});
var formatMonth = locale.format("%b"),
    formatDay = locale.format("%a"),
    formatDate = locale.format("%e"),
    x = locale.format("%X"),
    y = locale.format("%Y"),
    ti = locale.format("%Y/%-m/%-d"),
    ttt = locale.format("%Y/%-m/%-d %X"),
    date = new Date();
var d = formatMonth(date);
console.log(d); // "一月"
var d1 = formatDay(date);
console.log(d1); //星期五
var d2 = formatDate(date);
console.log(d2); //20
var d4 = x(date);
console.log(d4); //00:59:54
var d5 = y(date);
console.log(d5); //2017
var te = ti(date);
console.log(te); //2017/1/20
var tttt = ttt(date);
console.log(tttt); //2017/1/20 00:59:54

直接在js裏或者typescript裏寫出來能夠測試typescript

相關文章
相關標籤/搜索