//判斷日期是今天還是昨天還是以前
比如你昨天發(fā)了一條說說,我今天看就是顯示昨天幾時幾分葫督,明天看就是2016年7月14日 幾時幾分
NSTimeInterval _interval = [_dataArray[i][@"publishDate"] integerValue] / 1000.0;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
[self compareDate:date andModel:model]妆绞;
-(void)compareDate:(NSDate *)date andModel:(FaceModel *)model {
NSTimeInterval secondsPerDay = 24 * 60 * 60;
NSDate *today = [[NSDate alloc] init];
NSDate *yesterday;
yesterday = [today dateByAddingTimeInterval: -secondsPerDay];
NSString * todayString = [[today description] substringToIndex:10];
NSString * yesterdayString = [[yesterday description] substringToIndex:10];
NSString * dateString = [[date description] substringToIndex:10];
if ([dateString isEqualToString:todayString]) //今天
{
NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
[objDateformat setDateFormat:@"HH:mm"];
NSString *resultString = [objDateformat stringFromDate:date];
model.time = resultString;
} else if ([dateString isEqualToString:yesterdayString]) //昨天
{
NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
[objDateformat setDateFormat:@"HH:mm"];
NSString *resultString = [objDateformat stringFromDate:date];
model.time = [NSString stringWithFormat:@"昨天 %@",resultString];
}
else //以前
{
NSDateFormatter *objDateformat = [[NSDateFormatter alloc] init];
[objDateformat setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *resultString = [objDateformat stringFromDate:date];
model.time = resultString;
}
}
/**
* 版本升級
*/
- (void)versionUpgrade{
NSDictionary *dic = @{@"mobile" : @"0",
@"varsion_code" : @"9"};
[WSQNetWorking networkingPOSTWithActionType:loginAction requestDictionary:dic success:^(NSDictionary *responseObject) {
if ([responseObject[@"Dxbug"] integerValue] != 1) {
NSString *message;
UIAlertController *alertVC;
if ([responseObject[@"force"] integerValue] == 1) {
message = @"有新版本,并且為必須升級版本";
alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
}else{
message = @"有新版本必搞,是否升級版本?";
alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertVC addAction:cancelAction];
}
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"升級" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
[self versionUpgrade];
}];
[alertVC addAction:sureAction];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil];}
}
failure:^(NSError *error)
{ NSString *description = error.localizedDescription;
NSString *reason = error.localizedFailureReason;
NSString *errorMessage = [NSString stringWithFormat:@"%@ %@", description, reason];
[SVProgressHUD showErrorWithStatus:errorMessage maskType:SVProgressHUDMaskTypeBlack ];
}];
}
//日期轉(zhuǎn)為年齡
- (int)dateChangeAge:(NSString *)birth {
//計算年齡
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
//生日
NSDate *birthDay = [dateFormatter dateFromString:birth];
//當(dāng)前時間
NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
NSDate *currentDate = [dateFormatter dateFromString:currentDateStr];
NSTimeInterval time=[currentDate timeIntervalSinceDate:birthDay];
int age = ((int)time)/(3600*24*365);
return age;
}
/**
* 根據(jù)生日計算星座
*
* @param month 月份
* @param day 日期
*
* @return 星座名稱
*/
- (NSString *)calculateConstellationWithMonth: (NSInteger)month day:(NSInteger)day
{
NSString *astroString = @"魔羯水瓶雙魚白羊金牛雙子巨蟹獅子處女天秤天蝎射手魔羯";
NSString *astroFormat = @"102123444543";
NSString *result = [NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(month*2-(day < [[astroFormat substringWithRange:NSMakeRange((month-1), 1)] intValue] - (-19))*2,2)]];
return [NSString stringWithFormat:@"%@座",result];
}
iOS tips
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門癞谒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事弹砚∷裕” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵迅栅,是天一觀的道長殊校。 經(jīng)常有香客問我,道長读存,這世上最難降的妖魔是什么为流? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮让簿,結(jié)果婚禮上敬察,老公的妹妹穿的比我還像新娘。我一直安慰自己尔当,他們只是感情好莲祸,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著椭迎,像睡著了一般锐帜。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上畜号,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼疼蛾!你這毒婦竟也來了肛跌?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布鞠评,位于F島的核電站,受9級特大地震影響壕鹉,放射性物質(zhì)發(fā)生泄漏剃幌。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一晾浴、第九天 我趴在偏房一處隱蔽的房頂上張望负乡。 院中可真熱鬧,春花似錦脊凰、人聲如沸抖棘。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽切省。三九已至,卻和暖如春帕胆,著一層夾襖步出監(jiān)牢的瞬間朝捆,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- Xcode 收錄1 用戶截屏?xí)r觸發(fā)UIApplicationUserDidTakeScreenshotNotifi...
- 1贷盲、網(wǎng)絡(luò)請求封裝采用類方法還是單例模式?2剥扣、extern字符串常量巩剖,宏定義字符串常量怎么選?const常量有數(shù)據(jù)類...
- 1.問題描述(一):今天要給測試提供一個測試的版本,按照以往的正常流程,我選擇release 裝態(tài)下的我的發(fā)布證書...
- 前言 自己對 Method Swizzling 的誤解钠怯,希望能幫到有同樣誤解的朋友佳魔。 正文 在 Nshipster...
- 我們就像迷途的星光鞠鲜,卻仍嘗試把黑夜照亮宁脊。那年,我生死一線贤姆,獨自用力榆苞,趟過青春的河...... -1- 兩年前的這個...