你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS ʱ¼äºÍʱ¼ä´ÁÖ®¼äת»¯Ê¾Àý

IOS ʱ¼äºÍʱ¼ä´ÁÖ®¼äת»¯Ê¾Àý

編輯:IOS開發綜合

ÒÔºÁÃëΪÕûÊýÖµµÄʱ¼ä´Áת»»

ʱ¼ä´Áת»¯ÎªÊ±¼ä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 ʱ¼äºÍʱ¼ä´ÁÖ®¼äת»¯Ê¾Àý】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved