How to set date format retrieved from UIDatePicker

后端 未结 2 1000
别跟我提以往
别跟我提以往 2021-01-29 02:34

I am retrieving date from UIDatePicker ,now i want to convert in to wed, Dec29 12:30pm format , I also want to set that date to UIPickerView\'s current display date

2条回答
  •  离开以前
    2021-01-29 02:47

    You can use this code,its exactly what you want

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [NSTimeZone resetSystemTimeZone];
    NSTimeZone *gmtZone = [NSTimeZone systemTimeZone];
    [dateFormatter setTimeZone:gmtZone];
    [dateFormatter setDateFormat:@"day, MMM HH:mm:ss Z"];
    
    NSDate *dateT = [dateFormatter dateFromString:str1];
    
    NSString *strDateTaken=[appDelegate convertDate:dateT withFormat:@"EEEE, MMMM dd,yyyy hh:mm a"];
    [dateFormatter release];
    
    
    - (NSString *)convertDate:(NSDate *)date withFormat:(NSString *)format {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:format];
        NSString *dt = [formatter stringFromDate:date];
        [formatter release];
        return dt;
     }
    

    str1 is the date fetched in default format...

    Have fun!

提交回复
热议问题