How to set date format retrieved from UIDatePicker

后端 未结 2 997
别跟我提以往
别跟我提以往 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!

    0 讨论(0)
  • 2021-01-29 03:06

    if you use jquery:

    var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' });

    More general info available here:

    http://docs.jquery.com/UI/Datepicker#option-dateFormat

    http://docs.jquery.com/UI/Datepicker/formatDate

    regards

    magna

    0 讨论(0)
提交回复
热议问题