最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - How do I change the time format (12hr -> 24hr) in react-big-calendar on the draggable timeslot box? - Stack Ove

programmeradmin4浏览0评论

So I have the time correctly displaying in 24hr format in the actual events. but when I try to create a new event by dragging on the calendar grid, the dragged slot view is displaying the time period of that slot in 12hr format. when I create an event on that time slot, the event itself again shows in 24hr format. how to manipulate the actual dragged area?

I tried asking from ChatGPT (of course), but all the help it provided was mostly affecting the events themselves, which is not what I'm looking for.

Reproducing steps: put react-big-calendar to use, make it use 24hr clock with localizer prop. The end result is, that events show 24hr clock just fine, but when dragging on the timeline to create a new event, that element is in 12hr time format. The following code snippet is from the official documentation. I only changed the en-US locale to the Finnish variant.

import { Calendar, dateFnsLocalizer } from 'react-big-calendar'
import format from 'date-fns/format'
import parse from 'date-fns/parse'
import startOfWeek from 'date-fns/startOfWeek'
import getDay from 'date-fns/getDay'
import { fi } from 'date-fns/locale';

const locales = {
  'fi-FI': fi,
}

const localizer = dateFnsLocalizer({
  format,
  parse,
  startOfWeek,
  getDay,
  locales,
})

const MyCalendar = (props) => (
  <div>
    <Calendar
      localizer={localizer}
      events={myEventsList}
      startAccessor="start"
      endAccessor="end"
      style={{ height: 500 }}
    />
  </div>
)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论