简体   繁体   中英

How to get a weekday in Globalize?

In my project, I am using Globalize 1.1.1 .

It has the globalize for weekday in this path "dates/calendars/gregorian/days", I don't know how to get a specific day.

Like I want to get the Globalize for "Thuesday", the field is called "thu".

So my question is, How do I do it?

I had tried:

  • Globalize.dateParser({ raw: "weekday/wide" })( "thu" )
  • Globalize.formatUnit(1, "days", { form: "wide" })
  • Globalize.formatMessage("/dates/calendars/gregorian/days/wide/thu")

Use CLDR data directly

var dayNames = Globalize.cldr.main('dates/calendars/gregorian/days/format/wide');

// Access Thursday
dayNames.thu;

// Unrelated to question, but first day of week might be useful as well
var firstDay = dayNames[Globalize.cldr.supplemental.weekData.firstDay()];

Use date formatters

... or rely on date calculations, which are less dependent on cldr as noted by Rafael Xavier in this globalizejs issue on github.

So you would create a date, which you know is Tuesday, and specify a format giving you the weekday:

var formatter = Globalize.dateFormatter({raw: "EEEE"});
formatter(new Date(0, 0, 2));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM