ÒÔºÁÃëΪÕûÊýÖµµÄʱ¼ä´Áת»»
ʱ¼ä´Áת»¯ÎªÊ±¼ä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]; return dateString; }
ʱ¼äת»¯ÎªÊ±¼ä´Á
// µ±Ç°Ê±¼ä 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 ]; }
ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íû¶Ô´ó¼ÒµÄѧϰÓÐËù°ïÖú£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö½Å±¾Ö®¼Ò¡£
【IOS ʱ¼äºÍʱ¼ä´ÁÖ®¼äת»¯Ê¾Àý】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!