GithubHelp home page GithubHelp logo

日期时间选择组件,如果传入转换好时区的dayjs对象,理论上应该按照转换的时区渲染,America/New_York时区是没问题的,但是UTC时区有误 about ant-design HOT 8 CLOSED

CoCoManYY avatar CoCoManYY commented on May 8, 2024
日期时间选择组件,如果传入转换好时区的dayjs对象,理论上应该按照转换的时区渲染,America/New_York时区是没问题的,但是UTC时区有误

from ant-design.

Comments (8)

zombieJ avatar zombieJ commented on May 8, 2024 1

参考一下国际化示例:https://ant-design.antgroup.com/components/config-provider-cn#config-provider-demo-locale

DatePicker 内部格式化时间时会将当前上下文的 locale 提供进去以保持时区一致性:

date.locale(locale).format(format);

所以仅仅替换日期对象的时区是不够的,请参考例子完整的 extends dayjs 和 ConfigProvider locale。不完整填充下,不论看起来正确与否其实都是不正确的哈~

from ant-design.

zombieJ avatar zombieJ commented on May 8, 2024 1

你设置的 locale 是 dayjs.locale('en');,不是 UTC locale。

from ant-design.

stackblitz avatar stackblitz commented on May 8, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

from ant-design.

CoCoManYY avatar CoCoManYY commented on May 8, 2024

把locale补充上去也是一样。

https://stackblitz.com/edit/react-jembcu-pmykyp?file=demo.tsx

from ant-design.

CoCoManYY avatar CoCoManYY commented on May 8, 2024

感觉UTC是个特例,貌似没有对应的locale,我尝试改成 dayjs().tz('UTC').locale('en-gb') 也是一样的问题。 我如果传入 dayjs().utc() 则没问题。

from ant-design.

CoCoManYY avatar CoCoManYY commented on May 8, 2024

只转换时区,不考虑国际化的话,我应该是不需要手动设置locale的吧?

from ant-design.

yoyo837 avatar yoyo837 commented on May 8, 2024

dayjs.tz.setDefault('Asia/Shanghai'); ?

from ant-design.

CoCoManYY avatar CoCoManYY commented on May 8, 2024

dayjs.tz.setDefault('Asia/Shanghai'); ?

我的场景不能全局设置,需要根据组件局部配置的时区来,一个页面3个datepicker组件,可能时区都不相同

from ant-design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.