Skip to content

software-mansion-labs/react-native-hour-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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.

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'
	}
});