0

I am working on Application which has users in different countries. for example, India and US.

I want NSDate with out time in all case in any timezone.

For example, 2016-03-01 will be remain same in both timezones 2016-03-01 00:00:00 +0000.

I am using

NSDate* dateOnly = [[NSCalendar currentCalendar] dateBySettingHour:0 minute:0 second:0 ofDate:[NSDate date] options:NSCalendarMatchLast];

Still I am getting this: 2016-04-21 05:00:00 +0000

I need 2016-04-21 00:00:00 +0000

Please suggest proper solution. Thanks in advance.

Dimple Shah
  • 304
  • 3
  • 18

3 Answers3

2

This one should work

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSLog(@"%@", [dateDormatter stringFromDate:dateOnly]);
Mortgy
  • 543
  • 5
  • 9
1
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm";

NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];
NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];

Try above line of code. Hope it will help you.

Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51
0

Can you try?

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[dateFormatter setTimeZone:timeZone];

hope help you this

Community
  • 1
  • 1
hasankose
  • 303
  • 3
  • 10