Home > Software engineering >  how can you get the current local time on my device with the 12 hour format in React native?
how can you get the current local time on my device with the 12 hour format in React native?

Time:10-23

I am have an idea on how I could get the time but its always in 24 hour format, how can I get it into being in a 12 hour format??

any suggestions??

CodePudding user response:

You can use any js date-time library you prefer. For example https://date-fns.org/v2.29.3/docs/format Regarding getting the proper timezone, first, you need to get your device's timezone with

import DeviceInfo from 'react-native-device-info';

DeviceInfo.getTimezone();

and then use this timezone with date-time library https://date-fns.org/v2.29.3/docs/Time-Zones

CodePudding user response:

use Moment format to do that

moment().format("hh:mm a")
  • Related