简体   繁体   English

在 React 应用程序中从用户设备或浏览器获取短日期格式

[英]Get the Short Date Format from users device or browser in React application

I am working with reactjs and material UI datepicker.我正在使用 reactjs 和材料 UI 日期选择器。 I need to pass the short date format to the datepicker component (eg format="MM/dd/yyyy" ).我需要将短日期格式传递给 datepicker 组件(例如format="MM/dd/yyyy" )。 Also using the built-in date validation, I want to make this format dynamic and based on the user's preferred format in the device (windows, mac, ios, android) or the browser.同样使用内置的日期验证,我想根据用户在设备(windows、mac、ios、android)或浏览器中的首选格式使这种格式动态化。 Is there a way to get the date format in react?有没有办法让日期格式做出反应? Either through a library or pure JavaScript?通过库还是纯 JavaScript?

ie I'm using i18next for translation handling.即我正在使用i18next进行翻译处理。 Not sure if there's any function for handling date format as well.不确定是否还有用于处理日期格式的 function。 This is my first time working with this concept.这是我第一次使用这个概念。

i18next has a format function you can use to do whatever you want: https://www.i18next.com/translation-function/formatting i18next 具有 function 格式,您可以使用它来做任何您想做的事情: https://www.i18next.com/translation-function/formatting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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