標籤:style blog color os io for ar cti
//date根據formatter轉換成string+(NSString*)dateToString:(NSString *)formatter date:(NSDate *)date{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:formatter]; return[dateFormatter stringFromDate:date];}//string類型的時間戳記轉換成時間+(NSString*)dateStringToString:(NSString *)dateStr{ if ([dateStr isKindOfClass:[NSNull class]]) { return nil; } else { NSInteger time = [dateStr intValue]; NSDate *date = [NSDate dateWithTimeIntervalSince1970:time]; NSString *timestr = [NSString stringWithFormat:@"%@",date]; NSRange rang; rang.location = 0;O rang.length = 10; NSString *needtime = [timestr substringWithRange:rang]; return needtime; }}//將日期從原格式轉換成需要的格式+(NSString*)convertDateFormatter:(NSString*)sourceFormatter targetFormatter:(NSString*)targetFormatter dateString:(NSString*)dateString{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:sourceFormatter]; NSDate *date = [dateFormatter dateFromString:dateString]; [dateFormatter setDateFormat:targetFormatter]; return[dateFormatter stringFromDate:date];}//將日期文字轉換成date+(NSDate *)stringToDate:(NSString *)formatter dateString:(NSString *)dateString{ NSDateFormatter *dateFormatter= [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:formatter]; return [dateFormatter dateFromString:dateString];}