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

  • Home
  • SEARCH
  • 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 9090653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:25:26+00:00 2026-06-16T22:25:26+00:00

I have written the following method: – (NSDate *)stringToDate:(NSString *)dateString { // Convert string

  • 0

I have written the following method:

- (NSDate *)stringToDate:(NSString *)dateString
{
    // Convert string to date
    NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
    NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"America/New_York"];
    [dateFormat setDateFormat:@"M/d/yyyy HH:mm:ss"];
    [dateFormat setTimeZone:tz];
    NSDate * date = [dateFormat dateFromString:[NSString stringWithFormat:@"%@ 00:00:00", dateString]];

    return dateOnly;
}

When I call this with just a date such as 11/1/2013 or 11/13/2013 I get 2013-11-01 04:00:00 +0000 and 2013-11-13 05:00:00 +0000.

If I set a breakpoint on the return the date appears right, but if I break at in the calling function after this call, the date is returned with the time.

How come my time is not always 0. Can anyway tell me what is wrong in my function?

Thank you

UPDATE:

The input string is as follows: 11/1/2013 and 11/13/2013

  • 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-16T22:25:27+00:00Added an answer on June 16, 2026 at 10:25 pm

    NSDate is a point in time. It will always have a time component.
    And if not printed as a string form a NSDateFormatter, the Date and time will always be the one of UTC/GMT.


    The format and the date string must fit.

    NSString *dateString = @"11/1/2013";
    [dateFormat setDateFormat:@"M/d/yyyy"];
    

    The one hour apart comes from the Daylight saving time. Till November, 3rd 2013 New York has Summer time. http://www.timeanddate.com/worldclock/clockchange.html?n=179


    Ok, so can I ignore that? I am trying to compare NSDates when I do my comparison fails because of the time part

    You should create dates with with a time during the day — i.e. noon — to be save of DST mess and compare those. Use NSComponents for that.


    A must-see for any iOS/Cocoa-Developer: the fantastic WWDC 2011 Video “Session 117 – Performing Calendar Calculations”.

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

Sidebar

Related Questions

i have written the following code class Program { static void Main(string[] args) {
I have written the following method to detemine whether file in question is formatted
I have written the following line of code: NSMutableArray *array=[[NSMutableArray alloc]init]; This allocates some
I have written the following method to read data from a stream in general.
I have written the following method in a class that inherits from the Thread
I have written the following code, but continually get a 'non-static method getText() can
I have written the following method that prevents all keys from being pressed: private
I have written the following method to return a list of Unserializable classes (LINQ
I have written following method with three sql queries in order to update a
I have written the following in a JavaScript method : <html> ... <script type=text/javascript

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.