Properly support time locales

This commit is contained in:
Thomas Nordquist
2019-03-25 19:21:10 +01:00
parent ea7994dad9
commit 62cbf6547e
3 changed files with 13 additions and 3 deletions

View File

@@ -1,13 +1,22 @@
import * as React from 'react'
import * as moment from 'moment'
interface Props {
date: Date
}
class DateFormatter extends React.Component<Props, {}> {
public render() {
return <span>{this.props.date.toLocaleDateString()} {this.props.date.toLocaleTimeString()}</span>
const momentObject = this.localizedMoment()
return <span>{momentObject.format('L')} {momentObject.format('LTS')}</span>
}
private getLocale() {
return window.navigator.language
}
private localizedMoment() {
return moment(this.props.date).locale(this.getLocale())
}
}