以毫秒为整数值的时间戳转换
时间戳转化为时间NSDate
代码如下 | 复制代码 |
- (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // 格式化时间 NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
// 毫秒值转化为秒 NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0]; NSString* dateString = [formatter stringFromDate:date]; returndateString; } |
时间转化为时间戳
代码如下 | 复制代码 |
// 当前时间 NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0]; NSTimeInterval a=[date timeIntervalSince1970]*1000;// *1000 是精确到毫秒,不乘就是精确到秒 NSString *timeString = [NSString stringWithFormat:@"%.0f", a];//转为字符型 |
通过比较时间与当前时间返回年月日的方法
代码如下 | 复制代码 |
- (void)getBabyDetailAge:(NSString *)date { // 获得日期对象 NSDateFormatter *formatter_ = [[NSDateFormatter alloc] init]; formatter_.dateFormat = @"yyyy-MM-dd HH:mm:ss"; NSDate *createDate = [formatter_ dateFromString:date];
NSCalendar *gregorian = [[ NSCalendar alloc ] initWithCalendarIdentifier : NSCalendarIdentifierGregorian]; NSUInteger unitFlags = NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear; NSDateComponents *components = [gregorian components:unitFlags fromDate:createDate toDate:[NSDate date] options: 0 ];
NSInteger years = [components year]; NSInteger months = [components month ]; NSInteger days = [components day ]; } |
凡尔赛法环免广告版 最新版v1.69.1
下载天煞异种 安卓版v1.0.21
下载十三月 (Undecember)最新官方中文版v3.26.0200
下载我不是废柴无限99999钻999999金币游戏 不减反增版v1.2.16
下载我的女友是声优免广告 安卓版v1
我的女友是声优免广告是一款非常好玩的模拟经营类手游,玩家在游
石器帝国去广告版 v8
石器帝国免广告版是游戏的破解版本,在该版本中为玩家去除了广告
校园恋爱模拟器真人版去广告版 v0.0.7
校园恋爱模拟器真人版免广告版是游戏的破解版本,在该版本中为玩
教练我要开球馆内置菜单修改器 安卓版v1.5.4
教练我要开球馆内购版是一款模拟经营类游戏,玩家们将在游戏中创
我的游轮无限砖石 安卓版v1.7.0
我的游轮无限金币钻石版是一款模拟经营类游戏,你将成为一艘游轮