Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:11:00+00:00 2026-05-28T04:11:00+00:00

I am trying to convert nsstring to nsdate and then to the systemtimezone. Is

  • 0

I am trying to convert nsstring to nsdate and then to the systemtimezone. Is my code right? Any help appreciated.

NSString *str=@"2012-01-15 06:27:42";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateFromString = [dateFormatter dateFromString:str];

NSDate* sourceDate = dateFromString;

NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT-07:00"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];

NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;

NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];

bottomLabel2.text=[NSString stringWithFormat:@"- %@ -",destinationDate];

The code result is 2012-01-15 06:27:42 +0000 which is the same as the source!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:11:00+00:00Added an answer on May 28, 2026 at 4:11 am

    I think I can see what the problem is here – it’s this line:

    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT-07:00"];
    

    GMT-07:00 is not a valid abbreviation for this method. If you call [NSTimeZone abbreviationDictionary] you’ll get a dictionary containing all available abbreviations. You need to use the actual abbreviation (eg, ‘PST’ for Pacific Standard Time), and not the format “GMT-07:00”.

    To save you time, here’s the full list of supported abbreviations using NSTimeZone.

        ADT = "America/Halifax";
        AKDT = "America/Juneau";
        AKST = "America/Juneau";
        ART = "America/Argentina/Buenos_Aires";
        AST = "America/Halifax";
        BDT = "Asia/Dhaka";
        BRST = "America/Sao_Paulo";
        BRT = "America/Sao_Paulo";
        BST = "Europe/London";
        CAT = "Africa/Harare";
        CDT = "America/Chicago";
        CEST = "Europe/Paris";
        CET = "Europe/Paris";
        CLST = "America/Santiago";
        CLT = "America/Santiago";
        COT = "America/Bogota";
        CST = "America/Chicago";
        EAT = "Africa/Addis_Ababa";
        EDT = "America/New_York";
        EEST = "Europe/Istanbul";
        EET = "Europe/Istanbul";
        EST = "America/New_York";
        GMT = GMT;
        GST = "Asia/Dubai";
        HKT = "Asia/Hong_Kong";
        HST = "Pacific/Honolulu";
        ICT = "Asia/Bangkok";
        IRST = "Asia/Tehran";
        IST = "Asia/Calcutta";
        JST = "Asia/Tokyo";
        KST = "Asia/Seoul";
        MDT = "America/Denver";
        MSD = "Europe/Moscow";
        MSK = "Europe/Moscow";
        MST = "America/Denver";
        NZDT = "Pacific/Auckland";
        NZST = "Pacific/Auckland";
        PDT = "America/Los_Angeles";
        PET = "America/Lima";
        PHT = "Asia/Manila";
        PKT = "Asia/Karachi";
        PST = "America/Los_Angeles";
        SGT = "Asia/Singapore";
        UTC = UTC;
        WAT = "Africa/Lagos";
        WEST = "Europe/Lisbon";
        WET = "Europe/Lisbon";
        WIT = "Asia/Jakarta";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi Im trying to convert an NSString to NSDate NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]
I am trying to convert the following string into an NSDate object: NSString *str=@25
I am trying to convert string into NSDate using following code. NSString *old =
I'm trying to convert a NSString to an NSDate. If the iPhone region is
Trying to convert this c code into MIPS and run it in SPIM. int
I'm trying to convert old QuickTime framework code to the 64-bit Cocoa-based QTKit on
I'm trying to convert some code that worked great in VB, but I can't
I am trying to convert an string date to a NSDate to make some
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {
Hey, I am trying to convert NSString to a C string using cStringUsingEncoding but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.