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 6753597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:10:49+00:00 2026-05-26T13:10:49+00:00

I am loading in dates from my web service, I’m sending dates in the

  • 0

I am loading in dates from my web service, I’m sending dates in the format (GMT times): 02/11/11 10:56:09

I am creating an NSDate form this using NSDateFormatter as such:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
NSDate *journeyDate = [dateFormatter dateFromString:str];
[dateFormatter release];

This works great, after I’m comparing this to the current date to get relative time intervals.

The problem is when the phone is set up in a different timezone, when I load in the date from my api, and use the date formatter, what seems to be happening is the phone is assuming the date string is local time and it’s converting it to GMT.

Example:

I load in a date with the time 10am from the api.
The phone is set to PDT.
The date formatter is creating an NSDate assuming that my date string with 10am, is actually relevant to the phone.

I end up with a date and time equal to 5pm, adding 10 hours.

I am trying to specify in my date formatter that the string is GMT, but I’m having trouble, I’ve tried the following, adding GMT to the format:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss GMT"];
NSDate *journeyDate = [dateFormatter dateFromString:str];
[dateFormatter release];

This is not working.

Can anyone give any advice ?

Solution

Just a recap, I got it working with a terrible work around by appending GMT to the original string, and formatting that:

NSString * cheat = [NSString stringWithFormat:@"%@ GMT", str];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss zzzz"];
NSDate *journeyDate = [dateFormatter dateFromString:cheat];
[dateFormatter release];
return journeyDate;

This was a kind of unstable hack, because if the string changed to include a timezone, it wouldn’t work anymore. For anyone who needs to do as myself, the following is just a quick example on how to create an NSTimeZone.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDate *journeyDate = [dateFormatter dateFromString:str];
[dateFormatter release];
return journeyDate;

Thanks for the quick help.

  • 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-26T13:10:50+00:00Added an answer on May 26, 2026 at 1:10 pm

    I suspect you just want to use NSDateFormatter.setTimeZone to force it to use UTC. You don’t want to change the format string because presumably the string doesn’t include the letters “GMT” – instead, you want to change which time zone the string is interpreted in, which is what setTimeZone will do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pulling dates from an xml feed that has this form 12/10/2010 19:30:00 and
After loading a PHP template (using jQuery's load function), this simple script won't make
I have a json object that I'm loading from wordpress using the JSON API
I have a form that is loading quite an amount of data from SQL
I am using multithreading while loading data from the database. I am doing the
I am loading in a bunch of data that contains dates formatted as shown
When loading a page for the first time (!IsPostback), I am creating a button
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Assuming daily certain up to date database is produced via loading from various sources.
I have a jqgrid with data loading from an xml stream (handled by django

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.