How to get the current time instead of device time in iOS

后端 未结 2 520
小蘑菇
小蘑菇 2021-01-19 17:25

Im using [NSDate date] to get the current time. Everything works fine if user don\'t change the time...I mean if user changed manually instead of setting it au

2条回答
  •  清歌不尽
    2021-01-19 17:49

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];                               
    // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    
       NSString *startTime = [dateFormatter stringFromDate:startDateTime];                   
    
       NSString *endTime = [dateFormatter stringFromDate:endDateTime];
    
       NSLog(@"User's current time %@ and end Time %@ in their preference format",startTime,endTime);
    

提交回复
热议问题