获取当前时间的时分秒

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

    // 实例化日历对象
   
NSCalendar *calendar = [NSCalendar currentCalendar];
   
   
// 获取当前时间的秒数
   
NSDateComponents *comps = [calendar components:NSCalendarUnitSecond fromDate:[NSDate date]];
   
// 获取当前时间的分钟数
   
NSDateComponents *minute = [calendar components:NSCalendarUnitMinute fromDate:[NSDate date]];
   
// 获取当前时间的分钟数
   
NSDateComponents *hour = [calendar components:NSCalendarUnitHour fromDate:[NSDate date]];
  
// NSLog(@"%.2f", 10/0.3);
   
   
// 设置秒针的旋转
   
CGFloat angle = degree2angle(comps.second * 360 / 60);
   
self.secondView.transform = CGAffineTransformMakeRotation(angle);
   
// 设置分针的旋转
   
CGFloat angleM = degree2angle(minute.minute * 360 / 60);
   
self.minuteView.transform = CGAffineTransformMakeRotation(angleM);
   
// 设置时针的旋转
   
CGFloat angleH = degree2angle(hour.hour*30 + minute.minute/10.0 *5);
   
self.hourView.transform = CGAffineTransformMakeRotation(angleH);
  
// (hour*30) + (minutes/10)*6

转载于:https://my.oschina.net/u/2618362/blog/667845

你可能感兴趣的:(python)