Friday, May 3, 2013

NSTimeZone NSTimeZoneNameStyleShortStandard example ios


Specify styles for presenting time zone names.
typedef enum : NSInteger {
   NSTimeZoneNameStyleStandard,
   NSTimeZoneNameStyleShortStandard,
   NSTimeZoneNameStyleDaylightSaving,
   NSTimeZoneNameStyleShortDaylightSaving,
   NSTimeZoneNameStyleGeneric,
   NSTimeZoneNameStyleShortGeneric
} NSTimeZoneNameStyle;
Constants
NSTimeZoneNameStyleStandard
Specifies a standard name style. For example, “Central Standard Time” for Central Time.
NSTimeZoneNameStyleShortStandard
Specifies a short name style. For example, “CST” for Central Time.
NSTimeZoneNameStyleDaylightSaving
Specifies a daylight saving name style. For example, “Central Daylight Time” for Central Time.
NSTimeZoneNameStyleShortDaylightSaving
Specifies a short daylight saving name style. For example, “CDT” for Central Time.
NSTimeZoneNameStyleGeneric
Specifies a generic name style. For example, “Central Time” for Central Time.
NSTimeZoneNameStyleShortGeneric
Specifies a generic time zone name. For example, “CT” for Central Time.

Example of [NSTimeZone NSTimeZoneNameStyleShortStandard]
NSTimeZone *systimeZone = [NSTimeZone systemTimeZone];
    NSString *timeZoneString = [systimeZone localizedName:NSTimeZoneNameStyleShortStandard locale:[NSLocale currentLocale]];
    if([systimeZone isDaylightSavingTimeForDate:[NSDate date]]){
        timeZoneString = [systimeZone localizedName:NSTimeZoneNameStyleShortDaylightSaving locale:[NSLocale currentLocale]];
    }
 NSLog(@"%@",timeZoneString);

Example of [NSTimeZone NSTimeZoneNameStyleShortStandard]
 NSDateFormatter *inputFormatter = [[NSDateFormatter alloc]init];
    assert(inputFormatter != nil);
    NSLocale *loacle = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"];
    assert(loacle != nil);

    [inputFormatter setLocale:loacle];
    [inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];

    [inputFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

   NSString *dateString = [NSString stringWithFormat:@"%@",currentPubDate];
   NSDate *inputDate = [inputFormatter dateFromString:dateString];

    NSLocale *hebrow = [[NSLocale alloc]initWithLocaleIdentifier:@"he_IL"];
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
    outputFormatter.locale = hebrow;
    [outputFormatter setDateStyle:NSDateFormatterFullStyle];
    [outputFormatter setTimeStyle:NSTimeZoneNameStyleShortStandard];
    NSString *outputDate = [outputFormatter stringFromDate:inputDate];