How to format the date to IST?

前端 未结 3 782
天命终不由人
天命终不由人 2021-01-21 04:00

I have to format the date as below:

19-JUL-2014 10:27:16 IST

How can I do that? Should I send \"IST\" as string object?

I tried -

N         


        
3条回答
  •  梦谈多话
    2021-01-21 04:26

      NSDate* sourceDate = [NSDate date];
        NSLog(@"Date is : %@", sourceDate);
    
        NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
        NSLog(@"TimeZone is : %@", currentTimeZone);
    
        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init]  ;
        [dateFormatter setDateFormat:@"dd-MMM-yyyy HH:mm:ss zzz"];
        [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
    
        NSLog(@"%@",[dateFormatter stringFromDate:sourceDate]);
    

    This may help you

提交回复
热议问题