Get the Day from the date in iOS sdk

后端 未结 7 478
无人共我
无人共我 2021-01-16 12:36

In my app, want to get the day (i.e. Sunday, Monday,etc.) from the date.

My code is as follow:

NSDate *currentDate = [NSDat         


        
7条回答
  •  野的像风
    2021-01-16 13:33

    you face problem because it take local time zone

    try this

      NSDateFormatter *dateformate = [[NSDateFormatter alloc] init] ;
     [dateformate setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Sydney"]];
     [dateformate setDateFormat:@"EEEE"];
      NSLog(@"%@", [dateformate stringFromDate:[NSDate date]]);
      NSLog(@"%@", [NSTimeZone knownTimeZoneNames]);
    

    set time zone that you required.it may work and help you.

    similar problem in NSCalendar first day of week link refer it.also may help you.

提交回复
热议问题