Skip to content

Instantly share code, notes, and snippets.

@Hagbarth
Created November 18, 2015 01:24
Show Gist options
  • Save Hagbarth/dc7a4704bfbfc12a6794 to your computer and use it in GitHub Desktop.
Save Hagbarth/dc7a4704bfbfc12a6794 to your computer and use it in GitHub Desktop.
React native get local timezone from iOS system
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;
#import <Foundation/Foundation.h>
#import "RCTBridgeModule.h"
@interface HBTimezone : NSObject <RCTBridgeModule>
@end
#import "HBTimezone.h"
@implementation HBTimezone
RCT_EXPORT_METHOD(getTimezone:(RCTResponseSenderBlock)callback) {
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
callback(@[[NSNull null], currentTimeZone.name]);
};
RCT_EXPORT_MODULE();
@end
@Hagbarth
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment