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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:31:00+00:00 2026-06-05T17:31:00+00:00

I’m converting a string Jun 11, 2012 9:30 PM to an NSDate and I

  • 0

I’m converting a string “Jun 11, 2012 9:30 PM” to an NSDate and I keep getting 4 hours ahead for some reason. The funny thing is I’m using this same string to feed a UIDatePicker in a detailed view where I have to do the same conversion, and the UIDatePicker renders the time fine. Only when I now try to NSLog it in my main and detailed view do I have problems.

This is in my views :

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM dd, yyyy h:mma"];  
NSDate *dateFromString = [[[NSDate alloc] init]autorelease];

NSLog(@"DATE %@", _date);

dateFromString = [formatter dateFromString:_date];

NSLog(@"NSDATEFROMSTRING %@", dateFromString);

NSLog returns :

2012-06-11 00:02:09.136 LocalDeals[78090:207] DATE Jun 11, 2012 9:30 PM
2012-06-11 00:02:09.137 LocalDeals[78090:207] NSDATEFROMSTRING 2012-06-12 01:30:00 +0000

Even when I add:

[formatter setTimeZone:[NSTimeZone defaultTimeZone]];

I still get the same results from any time I choose. Any ideas? This is on the simulator by the way and yes my Region Format is set to United States.

  • 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-06-05T17:31:01+00:00Added an answer on June 5, 2026 at 5:31 pm

    When you NSLog an NSDate it will print the time as a GMT time zone
    In order to see the correct data you will have to convert the NSDate to string using stringFromDate

    NSDate *dateFromString = [[[NSDate alloc] init]autorelease];
    
    NSLog(@"DATE %@", _date);
    
    //Instead of nslog directly, use this stringFromDate:remindOn
    NSString *str = [formatter stringFromDate:dateFromString];
    NSLog(@"date is %@", str); //This will log the correct data
    

    The problem you are getting is not in the NSDate but it is in Logging it
    UPDATE In order to save the data to a file or database i would suggest that you save it like this

    NSTimeInterval timeInterval  = [dateFromString timeIntervalSince1970];
    

    Now when you read it again from the database you would do

    NSDate *data = [[NSDate alloc] initWithTimeIntervalSince1970:timeInterval]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.