WildThing
WildThing

Reputation: 1285

antd replace moment with dayjs

Docs: https://ant.design/docs/react/replace-moment

since moment is no longer maintained, I am replacing it with dayjs on ant design. The issue comes when using the datepicker, it always shows the time in the current browsers timezone.

my app allows the user to switch timezone and I want the date and time picker to show the date in current selected timezone instead of the default one. How do I do that?

for example if I am in Canada and I put my current timeZone as India, when I select the DatePicker and choose today, It shows today in Canadian time, not the indian one which I want.

How do I solve this issue?

Upvotes: 2

Views: 6958

Answers (1)

llama
llama

Reputation: 1651

import moment from 'moment'

<meta name="DC.date" content={moment(data?.publicationDate!).format('YYYY-MM-DD')}></meta> 

Becomes:

const dayjs = require('dayjs')
    
<meta name="DC.date" content={dayjs(data?.publicationDate!).format('YYYY-MM-DD') }></meta>

Use locale for time zones:

import 'dayjs/locale/es' // load on demand

dayjs.locale('es') // use Spanish locale globally

dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance

Upvotes: 1

Related Questions