-1

I am working on an application that creates alerts with calendar. I can correctly set alarms on correct dates. For example, I set an alarm for 4th of May 2017 1 PM.

When, I try to get the calendar event it returns me some other date in UTC.

enter image description here

As you can see, it returns me 10 AM on same day with UTC. I am wondering how can I get the exact date when I try to get it from calendar.

Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
birdcage
  • 2,638
  • 4
  • 35
  • 58
  • You need to correct the timezone, perhaps setting timezone in your custom calendar may help. – NeverHopeless May 04 '17 at 07:51
  • This should help, you just need to convert the date to your current timezone: http://stackoverflow.com/questions/29392874/converting-utc-date-format-to-local-nsdate – Sean Lintern May 04 '17 at 07:54

3 Answers3

1

You just need to convert UTC to your local timezone.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSDate *date1 = [dateFormatter dateFromString:@"2017-05-04 10:00:00"];

// change to a readable time format and change to local time zone
[dateFormatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
NSString *strCurrentLocalTimezoneDate = [dateFormatter stringFromDate:date1];
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
0

Date always takes current time zone until we changed other.If we print the Date it might be showing different but actually it takes current.

Shabbir Ahmad
  • 615
  • 7
  • 17
-1

// except this code you may have to set timeZone as well.

NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"MMM-dd-yyyy"];

NSDate *now = [[NSDate alloc] init];

NSString *dateString = [format stringFromDate:now];
    NSLog(@"%@",dateString);
Ajjjjjjjj
  • 669
  • 4
  • 12