How to set date format retrieved from UIDatePicker

2019-03-03 12:27发布

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条回答
Luminary・发光体
2楼-- · 2019-03-03 12: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!

查看更多
你好瞎i
3楼-- · 2019-03-03 13:04

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

查看更多
登录 后发表回答