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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:47:56+00:00 2026-06-08T14:47:56+00:00

I have developed an app which works alot with dates and also stores these

  • 0

I have developed an app which works alot with dates and also stores these as strings in core data using this method:

- (NSDate*) stringToDate{
   NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
   [dateFormat setDateFormat:@"yy-MM-dd HH:mm"];
   NSDate *date = [dateFormat dateFromString:self];

   return date;

}

Working with date/time is quite tricky – just alone the time difference between the system and the locale time – anyway the above method should take care of that. (So I hope, since formatting a NSDate to a NSString returns the correct local time instead of looking at the NSDate variable in debugger which shows a 2 hours difference in my case)

There are also many calculations like this:

    NSCalendar *calendar = [NSCalendar currentCalendar];   <------

    NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:someDate];

    NSInteger now_hour = [components hour];
    NSInteger now_minute = [components minute];
    NSInteger yearx =  [components year];
    NSInteger monthx =  [components month];
    NSInteger dayx =  [components day];

where I need to set/change/create certain dates/times, do calculations and retrieve/store them in core data again as NSStrings.

My question is about using the appropriate calendar.

Should I always write:

NSCalendar *calendar = [NSCalendar currentCalendar]; ?

or

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

and

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSRepublicOfChinaCalendar];

esp. depending on whether the app is used in Europe/USA vs China?

  • 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-08T14:47:58+00:00Added an answer on June 8, 2026 at 2:47 pm

    Your method stringToDate won’t actually exactly work, see QA1480. Short version: the NSDateFormatter unfortunately has two, slightly contradictory, roles — decoding and encoding specific text formats and converting dates for display. Because the latter is locale related, it’s the default. To ensure you get the former behaviour, you should explicitly set the en_US_POSIX locale, which is guaranteed exactly to honour your date string.

    That being said, you seem to be a little confused about what an NSDate is. It’s not an NSString or any other written representation of a date. It’s an abstract record of an exact moment. It’s therefore completely unrelated to the current calendar. The user’s calendar and locale will affect how dates are printed, but it doesn’t affect the dates themselves. Now is still now, however you write it. That’s why when you apply a formatter to a date you get a correct local date, but if you just log a date to the console then you get something abstract and not necessarily in your local time zone. NSDate has no concept of time zones or of different calendars.

    Core Data can store dates directly (ie, there’s no need whatsoever for you to convert to an from strings manually any more than there is for numeric values) so I’m not entirely sure what you’re getting at. But normal behaviour is to use currentCalendar when you want to display something for the user. That’ll display according to their time zone and other settings.

    As per the QA, for applying fixed date strings you should use a date formatter with an explicitly set locale and not think about the calendar at all.

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

Sidebar

Related Questions

I have developed my app using core data. It works fine in the simulator.
I have developed a blackberry app, in which I am using Persistent Storage to
I have developed a Cocos2d-X app with XCode which works perfectly when I launch
i have developed an app which executes sql jobs. When I click on execute
I have current a developed app which I am going to submit in just
I have enrolled in the iOS developer's program. I've developed an app which I
I have developed a system app for my rom which includes some native libraries.
I have developed an application which creates an outlook application using outlook object model.
I have developed a website using Asp.Net MVC which uses a SQL CE database
I had developed an application using Win32 C++ API(around 2 years back, which works

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.