本文主要是介绍dayjs将星期的第一天设置为周一,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
默认引入的dayjs
的语言是英文,一周的开始是星期日,当使用dayjs().startOf('week')
的时候,就不是周一而是周日了。
import dayjs from "dayjs"
import "dayjs/locale/zh-cn"
import updateLocale from "dayjs/plugin/updateLocale" //
import localeData from "dayjs/plugin/localeData" // 这个是可以查看国际化语言配置的插件,dayjs.extend(updateLocale)
dayjs.extend(localeData)
dayjs.locale("zh-cn")
dayjs.updateLocale("zh-cn", {weekStart: 1// 配置为周一
})
Day.js 的语言对象模版
const localeObject = {name: 'es', // name Stringweekdays: 'Domingo_Lunes ...'.split('_'), // weekdays ArrayweekdaysShort: 'Sun_M'.split('_'), // OPTIONAL, short weekdays Array, use first three letters if not providedweekdaysMin: 'Su_Mo'.split('_'), // OPTIONAL, min weekdays Array, use first two letters if not providedweekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday。yearStart: 4, // OPTIONAL, the week that contains Jan 4th is the first week of the year.months: 'Enero_Febrero ... '.split('_'), // months ArraymonthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not providedordinal: n => `${n}º`, // ordinal Function (number) => return number + outputformats: {// abbreviated format options allowing localizationLTS: 'h:mm:ss A',LT: 'h:mm A',L: 'MM/DD/YYYY',LL: 'MMMM D, YYYY',LLL: 'MMMM D, YYYY h:mm A',LLLL: 'dddd, MMMM D, YYYY h:mm A',// lowercase/short, optional formats for localizationl: 'D/M/YYYY',ll: 'D MMM, YYYY',lll: 'D MMM, YYYY h:mm A',llll: 'ddd, MMM D, YYYY h:mm A'},relativeTime: {// relative time format strings, keep %s %d as the samefuture: 'in %s', // e.g. in 2 hours, %s been replaced with 2hourspast: '%s ago',s: 'a few seconds',m: 'a minute',mm: '%d minutes',h: 'an hour',hh: '%d hours', // e.g. 2 hours, %d been replaced with 2d: 'a day',dd: '%d days',M: 'a month',MM: '%d months',y: 'a year',yy: '%d years'},meridiem: (hour, minute, isLowercase) => {// OPTIONAL, AM/PMreturn hour > 12 ? 'PM' : 'AM'}
}
这篇关于dayjs将星期的第一天设置为周一的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!