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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:15:58+00:00 2026-05-26T15:15:58+00:00

I frequently use the NSDate compare method – but I want to consider two

  • 0

I frequently use the NSDate compare method – but I want to consider two dates similar if they are equal in year, month, day. I have made a procesure called “cleanDate” to remove the hour part before I compare.

-(NSDate*)cleanDate:(NSDate*)date {
    NSCalendarUnit unitflags;
    NSDateComponents *component;  
    NSCalendar *calendar;
    calendar=[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
    unitflags=NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    component=[calendar components:unitflags fromDate:date];
    return [calendar dateFromComponents:component]; //Dato uten klokke    
}

But my dates come out as:

2011-10-28 22:00:00
and some dates as:
2011-10-28 23:00:00

I want the hour part to be similar, e.g. 00:00.

Whats wrong? Does it have something to do with daylight saving time? Other? Thanks.

  • 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-26T15:15:59+00:00Added an answer on May 26, 2026 at 3:15 pm

    Seems like this is a Time Zone issue…
    I thought NSLog would default to the local time zone – but it seems to default to GMT…

    Date with GMT time zone is: Sat, 29 Oct 2011 22:00:00 GMT+00:00
    Date with system time zone is: Sun, 30 Oct 2011 00:00:00 GMT+02:00
    NSlog shows 2011-10-29 22:00:00 +0000
    
    When using NSLog(@"NSlog shows %@",finalDate); it seems to print the GMT time... 
    When using this code - I will get the local date in my time zone:
    
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"];
    [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
    NSString *dateString = [dateFormatter stringFromDate:myDate];
    NSLog(@"Date with system time zone is: %@",dateString);
    

    … so my original cleanDate actually seems to do what I want after all…

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

Sidebar

Related Questions

I frequently use the STL containers but have never used the STL algorithms that
I frequently use git stash and git stash pop to save and restore changes
I frequently use HTML output in applications, up to now I've used some simple
I frequently use the following pattern to set an upper bound to the running
I use Visual C++ 2008 in Visual Studio 2008. I frequently use the following
Hi I have SVN repo that I frequently use for change management. However after
I am using NetBeans for PHP 6.5. In my code I frequently use the
People use frequently something like: <ListBox ItemsSource={Binding ElementName=thisControl, Path=ListIndexes}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Label Content={Binding
I frequently make use of Request.QueryString[] variables. In my Page_load I often do things
I have a 'foreach' macro I use frequently in C++ that works for most

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.