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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:27:42+00:00 2026-05-27T00:27:42+00:00

In my app I need to create an event in the Calendar programmatically, all

  • 0

In my app I need to create an event in the Calendar programmatically, all the algorithm works around dates created by method + (id)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds. But with this method I cannot create an event, it seems that it does not have timezone set inside somewhere, because with other methods (i.e. [NSDate date]) event is created successfully.

My solution was to convert NSDate to CFGregorianDate, set timezone and convert back. It seems a bit long I guess.

Code snippet:

EKEvent *event = [EKEvent eventWithEventStore:eventStore];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:1322045010]; // interval is in seconds

NSLog(@"%@", date);
event.title = @"Test";
event.startDate = date;
event.endDate = date;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
[event addAlarm:[EKAlarm alarmWithAbsoluteDate:date]];

[eventStore saveEvent:event span:EKSpanThisEvent error:nil];

So my question is – why is it not possible to create an event with NSDate initialized with + (id)dateWithTimeIntervalSince1970:(NSTimeInterval)seconds? And could somebody suggest more robust way to solve this problem, I would be very grateful.

Artem

  • 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-27T00:27:43+00:00Added an answer on May 27, 2026 at 12:27 am

    Your error is revealed when you said this: “it seems that it does not have timezone set inside somewhere, because with other methods (i.e. [NSDate date]) event is created successfully.”

    No NSDate has any timezone information inside it. They are all referenced to GMT. The NSDateFormatter class is usually used to present them in the local timezone. And judging by your response to the comments above I doubt you believe me now. Test this out, in some method somewhere run this line of code.

    NSLog(@"[NSDate date] = %@",[NSDate date]);
    

    According to your user profile you are in Estonia. By my quick search you should be GMT+2:00(I’m sorry if I’m mistaken on your time zone) so the time you see in your console should be 2 hours behind. And I’m sure it is. The same as mine is 5 hours ahead.

    You can also tell I am right by your solution: “My solution was to convert NSDate to CFGregorianDate, set timezone and convert back. It seems a bit long I guess.”
    So basically you adjusted for the timezone and it works fine, Makes sense.

    But to your real question ‘Could somebody suggest a more robust way to solve this problem?’ The answer is relatively simple.

    Let’s say your server is returning the time interval since 1970 in estonian time (Eastern Europe?). All you have to do is adjust that time interval to point to the GMT time. Again if I’m wrong on the specifics of your time zone I apologize.

    NSTimeInterval estoniaTimeZoneDifference = 60*60*2;//60 seconds, 60 minutes, 2 hours
    NSDate *adjusted = [NSDate dateWithTimeIntervalSince1970:(timeIntervalSince1970FromServer - estoniaTimeZoneDifference)];
    // Here we subtract because this zone is 2 hours ahead of GMT.
    

    Again this adjustment would be indexed to the servers response.

    Edit: In response to:

    I agree with some points of your answer, but try to create an event on
    the date you just created, I bet your chances to do it are not very
    good.

    To quote a well know TV character “Challenge accepted!”.

    So I set out to test if an event could be successfully created using dateWithTimeIntervalSince1970:. And as I expected I found no flaw in NSDate or in the EventKit framework. I used this code:

    NSTimeInterval rightNowInterval = [[NSDate date] timeIntervalSince1970];
        //NSTimeInterval is a double, thus nothing up my sleeve.
    NSTimeInterval intervalSince70ToFire = rightNowInterval + 120;
        // Two minutes from whenever now is. Plus this is another layer of indirection to prove there's no 'magic' to [NSDate date]
    
    
        //Create fire date from dateWithTimeIntervalSince1970
    NSDate *fireDate = [NSDate dateWithTimeIntervalSince1970:intervalSince70ToFire];
    
        // Insert boilerplate event code
    EKEventStore *eventSotre = [[EKEventStore alloc] init];
    EKEvent *event = [EKEvent eventWithEventStore:eventSotre];
    event.title= @"Event Title"; 
    event.startDate = fireDate;
    event.endDate= [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
    [event addAlarm:[EKAlarm alarmWithAbsoluteDate:fireDate]];
    event.calendar = [eventSotre defaultCalendarForNewEvents];
    NSError *err = nil;
    if([eventSotre saveEvent:event span:EKSpanThisEvent error:&err]){
        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:@"Event added in calendar" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertview show];
    }
    else{
        UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:[err description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertview show];
    }
    

    When I run this code I get the “Event added in calendar” message. The two minutes gives me plenty of time to go to calendar and see that an event has in fact been correctly scheduled. And exit and wait for my alarm to go off. And it does.

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

Sidebar

Related Questions

Actually I need to create an event in Google Calendar using my app. Every
All, I need to create an app for work that signs into our website
I need to be able to create an event in the Google Calendar from
I need to create reports in a C# .NET Windows app. I've got an
I need to create a command line look-and-feel in a WPF app. In WPF,
In my app, I create view controller objects as I need them. When a
Hi im trying to create a simple android app using the Eclipse IDE, all
My app creates calendar events, where the event's description has a contact name in
I'm handling the Application.UnhandledException event in a WinForms app and need to log exceptions
I'm currently developing an app for selling tickets to an event. I'm in need

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.