https://github.com/pankajkgarg/react-native-truetime
TrueTime library for React native to get accurate time from ntp servers
https://github.com/pankajkgarg/react-native-truetime
ntp react-native time truetime
Last synced: about 1 year ago
JSON representation
TrueTime library for React native to get accurate time from ntp servers
- Host: GitHub
- URL: https://github.com/pankajkgarg/react-native-truetime
- Owner: pankajkgarg
- Created: 2017-11-20T06:27:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-20T06:56:25.000Z (over 8 years ago)
- Last Synced: 2025-04-14T07:19:05.127Z (about 1 year ago)
- Topics: ntp, react-native, time, truetime
- Language: Java
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-native-truetime
## Getting started
`$ npm install react-native-truetime --save`
### Mostly automatic installation
`$ react-native link react-native-truetime`
### Manual installation
#### Android
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
- Add `import com.pkgarg.truetime.RNTrueTimePackage;` to the imports at the top of the file
- Add `new RNTrueTimePackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-truetime'
project(':react-native-truetime').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-truetime/android')
```
3. Add maven repository to `android/build.gradle`:
```
allprojects {
repositories {
maven { url "https://jitpack.io" } // Add this line
}
}
```
4. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-truetime')
compile 'com.github.instacart.truetime-android:library-extension-rx:3.3'
```
## Usage
```javascript
import RNTrueTime from 'react-native-truetime';
// Initialize TrueTime
RNTrueTime.initTrueTime()
// Returns time in millisecond (as a string)
...
const trueTimeStr = await RNTrueTime.getTrueTime();
const trueTime = parseInt(trueTimeStr);
```