[英]How to convert arbitrary time to NSDate to format it using NSDateFormatter?
[英]how to convert nsdate to another format using nsdateformatter
我有2014年2月23日這種格式的日期字符串來自網絡服務,我想將其轉換為這種格式2014年2月23日,我正在嘗試很多,但一直以來nsstring返回我的null值
NSDateFormatter *DateFormatter=[[NSDateFormatter alloc] init];
[DateFormatter setDateStyle:NSDateFormatterMediumStyle];
[DateFormatter setDateFormat:@"MM-dd-yyyy"];
// date formatter two
NSDate *dateVal = (NSDate *)bookDetail.classdate;
NSLog(@"date %@",dateVal);
NSString *dateTwo = [DateFormatter stringFromDate:dateVal];
NSLog(@"new date string %@",dateTwo);
NSString *dateString = @"Feb 23, 2014";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
NSDate *date = [dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
NSString *newDateString = [dateFormatter stringFromDate:date];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.