
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
react-native-device-time-format
Advanced tools
Get device setting for time format in react-native
On mobile devices users have the option to opt in/out, of the systems locale, in regards to 12/24 hour clock format:
This package exposes this device setting for iOS & Android.
This package was heavily inspired by react-native-device-clock-format, which is "no longer actively maintained", and only supports iOS.
Thank you 🙏
Install with your preferred package manager:
yarn add react-native-device-time-format
or
npm install react-native-device-time-format --save &&
For iOS, install pod:
(cd ios/ && pod install)
For React Native < 0.60
, run:
react-native link react-native-device-time-format
Should the automatic linking fail (in case of folder structure mismatch or various other reasons), please follow the manual installation guide.
Bellow is an example of fetching the hours & minutes string representation from a date, with the device time format (using moment for date/time formatting):
import { is24HourFormat } from 'react-native-device-time-format'
import moment from 'moment'
/**
* @function getCurrentHourFormat
* @param {Date} date Date to format
* @return {Promise<string>} formatted string HH:mm / h:mm A, depending on device setting
*/
const getCurrentHourFormat = async (date) => {
const is24Hour = await is24HourFormat()
return moment(date).format(is24Hour ? 'HH:mm' : 'h:mm A'))
}
All native modules runs asynchronous, I would suggest updating an internal state in your app when AppState
changes to active.
FAQs
Get device setting for time format in react-native
The npm package react-native-device-time-format receives a total of 11,164 weekly downloads. As such, react-native-device-time-format popularity was classified as popular.
We found that react-native-device-time-format demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.