如何格式化字符串日期和时间到2012年12月4日星期二下午5点30分

时间:2016-12-28 11:50:44

标签: ios objective-c iphone xcode nsdateformatter

我对NSString *str = [detailsdict objectForKey:@"doc_appointments_Time"]; //time format is 5:30:00 PM NSString *dateandtime=[NSString stringWithFormat:@"%@, %@",[detailsdict objectForKey:@"doc_appointments_Date"],str]; //date format is 10/25/2016 cell.detailTextLabel.text=dateandtime;

中的日期和时间字符串转换为( temaplateObj.name: obj.name, ^ SyntaxError: Unexpected token . )有一点疑问
 var temaplateObj = {};    
 res.render('modules/users/server/templates/getdeals', {
    temaplateObj.name: obj.name,
    temaplateObj.from: common.tokenInfo.name,
    temaplateObj.appName: 'GAIPP',
    temaplateObj.company: company,
    temaplateObj.logo: logo,
    temaplateObj.url:url
  }, 

1 个答案:

答案 0 :(得分:3)

首先,您需要在使用NSDateFormatter之后合并日期和时间字符串,以便以您希望的格式生成日期。

NSString *stringDate = [NSString stringWithFormat:@"%@ %@",[detailsdict objectForKey:@"doc_appointments_Date"], [detailsdict objectForKey:@"doc_appointments_Time"]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
NSDate *date = [formatter dateFromString:stringDate];
[formatter setDateFormat:@"EEEE d MMMM yyyy,h:mm a"];
NSString *formattedDate = [formatter stringFromDate:date];