答案 0 :(得分:1)
用于获取浏览器语言的javascript解决方案:
import React from 'react';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import Main from './Main';
import Form from './Form';
const Content = () => (
<div>
<Main />
</div>
)
const FormEntry = () => (
<div>
<Form />
</div>
)
const Routes = () => (
<Router>
<div>
<ul>
<li><Link to="/">Home</Link></li>
<li><Link to="/form">Form</Link></li>
</ul>
<hr/>
<Route exact path="/" component={Content}/>
<Route path="/form" component={FormEntry}/>
</div>
</Router>
)
export default Routes;
然后可以将语言与toLocalDateString()结合使用以获取正确的日期格式,例如:
var lang = window.navigator.userLanguage || window.navigator.language;
console.log(lang); //example output: 'en-GB'
您可以像这样在selenium中执行javascript:
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
var lang = window.navigator.userLanguage || window.navigator.language;
alert(date.toLocaleDateString(lang));
我希望这会有所帮助。