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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:32:57+00:00 2026-05-31T13:32:57+00:00

I have been browsing the apple docs and stackoverflow for a while now, but

  • 0

I have been browsing the apple docs and stackoverflow for a while now, but I wasn’t be able to find a correct answer for my problem.
I’ll try to explain. In my app a user is able to create measurements on a specific time. The date and time of the measurement is important.

In my NSDate+Helper category I created the following helper methods:

- (NSDate *)dateByMovingToBeginningOfDay
{
    unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self];
    [parts setHour:0];
    [parts setMinute:0];
    [parts setSecond:0];
    return [[NSCalendar currentCalendar] dateFromComponents:parts];
}

- (NSDate *)dateByMovingToEndOfDay {
    unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self];
    [parts setHour:23];
    [parts setMinute:59];
    [parts setSecond:59];
    return [[NSCalendar currentCalendar] dateFromComponents:parts];
}

This methods helps me to get a range of measurements from a complete day:

NSDate *start = [[NSDate date] dateByMovingToBeginningOfDay];
NSDate *end   = [[NSDate date] dateByMovingToEndOfDay];

NSMutableSet *measurementsSet = [trainingsPlan measurementsWithType:@"used" fromDate:start andToDate:end];

There is where my problem comes in. Let’s say I add a measurement on my simulator at 2012-03-14 0:42:59 (GMT+1) -because that’s the time displayed on my simulator- and save it in core data.

[NSDate date] at that moment is 2012-03-13 23:42:59 so NSDate *start = [[NSDate date] dateByMovingToBeginningOfDay]; gives me the start date of the day before. This is a problem.

My question, what is the best approach that it will work for users in all different timezones?

  • 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-31T13:32:58+00:00Added an answer on May 31, 2026 at 1:32 pm

    If you want to use the same data across multiple time zones then your only option is to use the same timezone in your app, no matter what time the iPad says. Generally you use UTC for this purpose (and is the default time zone that times are created and saved in).

    If you just want it to match the local timezone, then you need to change your routines like this:

    - (NSDate *)dateByMovingToBeginningOfDay
    {
        NSCalendar *calendar = [NSCalendar currentCalendar];
        [calendar setTimeZone:[NSTimeZone localTimeZone]];
    
        unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    
        NSDateComponents* parts = [calendar components:flags fromDate:self];
        [parts setHour:0];
        [parts setMinute:0];
        [parts setSecond:0];
    
        return [calendar dateFromComponents:parts];
    }
    

    Update the second routine in the same way.

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

Sidebar

Related Questions

I have been browsing this site for the answer but I'm still a little
I have been browsing the web looking for caching information but cannot find anything
I have been browsing SO and various other sites to find out whether this
I've been browsing the forums a while trying to find a solution to my
I have been browsing around to find a way to disable closing Firefox 7
I have been browsing the reference section on Android.com and couldn't quite find the
Probably a simple question, but I've been browsing now for 30 mins and STILL
I have been browsing the web lately to find a good Web UI kit.
Of late I have been diving deep into web application security. While browsing I
I have been browsing around on the internet and researching effective sitemap web pages.

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.