How to set date format retrieved from UIDatePicker
I am retrieving date from UIDatePicker ,now i want to convert in to wed, Dec29 12:30pm format , I also want to set that 开发者_JAVA技巧date to UIPickerView's current display date
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!
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
精彩评论