Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/software-mansion-labs/react-native-hour-format
Get hour format from OS settings.
https://github.com/software-mansion-labs/react-native-hour-format
24 24hour am format hour moment momentjs pm react-native
Last synced: about 2 months ago
JSON representation
Get hour format from OS settings.
- Host: GitHub
- URL: https://github.com/software-mansion-labs/react-native-hour-format
- Owner: software-mansion-labs
- License: mit
- Created: 2017-12-13T11:29:52.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-13T14:04:06.000Z (over 5 years ago)
- Last Synced: 2024-04-22T01:55:02.484Z (9 months ago)
- Topics: 24, 24hour, am, format, hour, moment, momentjs, pm, react-native
- Language: Java
- Homepage:
- Size: 18.6 KB
- Stars: 28
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-react-native - react-native-hour-format ★20 - Get hour format from OS settings. (Components / Utils & Infra)
README
# react-native-hour-format
Get hour format from OS settings.## Installation
Add as dependency:```
npm i --save react-native-hour-format
```Link with react-native:
```
react-native link react-native-hour-format
```## Usage
There are three methods you can call:
```js
import { HourFormat } from 'react-native-hour-format';HourFormat.is24HourFormat() // bool
HourFormat.getHourFormat() // 12 or 24
HourFormat.getLocale() // string with system locale
```## Integration with `momentjs`
Use below snippet so `moment().format('LT')` will return correctly formated values.
```js
import { HourFormat } from 'react-native-hour-format';
import moment from 'moment';const is24HourFormat = HourFormat.is24HourFormat();
moment.updateLocale('en', {
longDateFormat: {
LT: is24HourFormat ? 'HH:mm' : 'hh:mm a',
LTS: is24HourFormat ? 'HH:mm:ss' : 'hh:mm:ss a'
}
});
```