Created
November 18, 2015 01:24
-
-
Save Hagbarth/dc7a4704bfbfc12a6794 to your computer and use it in GitHub Desktop.
React native get local timezone from iOS system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {NativeModules} from 'react-native' | |
const {HBTimezone} = NativeModules; | |
const getTimezone = () => new Promise((resolve, reject) => | |
HBTimezone.getTimezone((err, res) => { | |
if (err) return reject(new Error(err)); | |
return resolve(res); | |
}) | |
); | |
export default getTimezone; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "RCTBridgeModule.h" | |
@interface HBTimezone : NSObject <RCTBridgeModule> | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "HBTimezone.h" | |
@implementation HBTimezone | |
RCT_EXPORT_METHOD(getTimezone:(RCTResponseSenderBlock)callback) { | |
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone]; | |
callback(@[[NSNull null], currentTimeZone.name]); | |
}; | |
RCT_EXPORT_MODULE(); | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't find an easy way to just get the local timezone from the system on iOS, so I created this small bridge module.