Properly support time locales
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user