1 | initial version |
There are a few ways to alter the background image in React Native according to the time zone:
const currentTime = new Date();
const currentHour = currentTime.getHours();
const currentZone = currentTime.getTimezoneOffset();
if (currentZone === 240) { // Eastern Time Zone
background = require('./eastern-timezone.jpg');
} else if (currentZone === 300) { // Central Time Zone
background = require('./central-timezone.jpg');
} else {
background = require('./default-background.jpg');
}
import moment from 'moment-timezone';
const currentZone = moment.tz.guess();
if (currentZone === 'America/New_York') { // Eastern Time Zone
background = require('./eastern-timezone.jpg');
} else if (currentZone === 'America/Chicago') { // Central Time Zone
background = require('./central-timezone.jpg');
} else {
background = require('./default-background.jpg');
}
import Geolocation from 'react-native-geolocation-service';
Geolocation.getCurrentPosition((position) => {
const lat = position.coords.latitude;
const long = position.coords.longitude;
const currentZone = Geolocation.getTimeZone(lat, long);
if (currentZone === 'America/New_York') { // Eastern Time Zone
background = require('./eastern-timezone.jpg');
} else if (currentZone === 'America/Chicago') { // Central Time Zone
background = require('./central-timezone.jpg');
} else {
background = require('./default-background.jpg');
}
}, (error) => {
console.log(error);
});