标签: nstimeinterval

如何在iPhone中获得时差

我有2个带有时间值的数组.它们采用以下格式.mm:ss:几百秒.我想得到数组中两个[lastObjects]之间的区别.NSDate无法正常工作,因为最后一个值是百分之一秒.

一个问题.如果第二个日期大于第一个日期,它会给我一个负数,如-01:10:00?

iphone objective-c nsdate nstimeinterval

7
推荐指数
1
解决办法
2万
查看次数

如何正确使用NSTimeInterval?

我是Xcode的新手,我有以下问题:

我想要一种方法,它给了我从给定日期到现在已经过去的时间.如果它是2年前我想要返回一个字符串"2年前",但如果它是5分钟前我希望它返回一个字符串"5分钟前".

我已经检查过NSTimeInterval和NSDateFormatter,但我找不到让它工作的方法.

cocoa-touch objective-c nsdate nstimeinterval ios

7
推荐指数
1
解决办法
4万
查看次数

准确地从NStimeInterval转换为CMTime

我正在使用两个玩家MPMoviePlayerController,另一个是AVPlayer.henever MPMoviePlayerController是seeked,它设置的时间AVPlayer.一切都很好.将转换MPMoviePlayerController当前时间转换CMTime为ex :(如果mpplayer时间为11.80132,它将四舍五入为11).

如果没有四舍五入,我们如何设定时间AVPlayer

获取mpplayer时间和发送到AVPlayer课堂的代码

[avplayerClass  setCurrentTime:[self.videoPlayer currentPlaybackTime]];
NSLog(@"CurrentTime:%f",[self.videoPlayer currentPlaybackTime]);//11.801345
Run Code Online (Sandbox Code Playgroud)

AVPlayer类中的代码并将时间转换为CMTime

-(void)setCurrentTime:(NSTimeInterval)seekTime
{
    CMTime seekingCM = CMTimeMake(seekTime, 1);
    [self.player seekToTime:seekingCM 
            toleranceBefore:kCMTimeZero 
             toleranceAfter:kCMTimePositiveInfinity];
    [self.player seekToTime:seekingCM];
    NSLog(@"Current time123ns%%%%%%:%f",CMTimeGetSeconds(seekingCM));//11
    NSLog(@"Current time123ns%%%%%%:%f",seekTime);//11.801345
}
Run Code Online (Sandbox Code Playgroud)

objective-c mpmovieplayercontroller nstimeinterval avplayer cmtime

7
推荐指数
1
解决办法
8077
查看次数

在swift 3中获得两次时间差

我有2个变量,我从datePicker获得2次,我需要在变量上保存它们之间的差异.

    let timeFormatter = DateFormatter()
    timeFormatter.dateFormat = "HHmm"

    time2 = timeFormatter.date(from: timeFormatter.string(from: datePicker.date))!
Run Code Online (Sandbox Code Playgroud)

我试图从他们两个得到timeIntervalSince1970并且他们减去它们并得到毫秒的差异,我将回到小时和分钟,但是我得到一个非常大的数字,它与实际时间不对应.

let dateTest = time2.timeIntervalSince1970 - time1.timeIntervalSince1970
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用time2.timeIntervalSince(date:time1),但结果毫秒再次远远超过实际时间.

我怎样才能得到2次正确的时差,并以8小时23分钟的格式"0823"得到小时和分钟的结果?

nstimeinterval swift3

7
推荐指数
4
解决办法
2万
查看次数

NSTimeInterval到unix时间戳

我从CMMotionManager获取 CMDeviceMotion对象.CMDeviceMotion的一个属性是时间戳,表示为NSTimeInterval(double).根据文档,这允许"亚毫秒"时间戳精度.

[motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error) { 
  NSLog(@"Sample: %d Timestamp: %f ",counter,  motion.timestamp);
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,NSTimeInterval是自上次设备启动以来计算的,对以原始形式使用它提出了重大挑战.

有没有人有一个工作代码将此NSTimeInterval转换为类似时间戳(UTC时区)的Unix?

谢谢!

timestamp nstimeinterval ios core-motion

6
推荐指数
1
解决办法
6164
查看次数

将NSTimInterval转换为Integer Swift

我需要将NSTimeInterval类型的变量(我知道是Double)转换为Integer.我已经尝试过这里的解决方案:如何将NSTimeInterval转换为int?,没有成功.任何人都可以在Swift中提供有关如何执行此操作的任何建议吗?以下是我的功能:

func getHKQuantityData(sampleType: HKSampleType, timeUnit: NSCalendarUnit, startDate: NSDate, endDate: NSDate, completion: (Void -> Void)) -> [(NSDate, Double)] {
    var startTime = 0
    var endTime = 0
    var repeat: NSTimeInterval
    var returnValue: [(NSDate, Double)] = []
    var queryType: String = ""
    var predicate: NSPredicate!
    let timeInterval = endDate.timeIntervalSinceDate(startDate)
    switch sampleType {
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount):
        queryType = "step"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeight):
        queryType = "height"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass):
        queryType = "weight"
    case HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMassIndex):
        queryType = "bmi"
    default:
        println("No recognized type")
    }

    switch timeInterval { …
Run Code Online (Sandbox Code Playgroud)

nstimeinterval swift

6
推荐指数
1
解决办法
8949
查看次数

使用NSTimer进行HH:MM:SS?

如何更改此代码,使其具有HH:MM:SS(小时,分钟,秒,

你能告诉我是否需要在.h或.m中添加代码以便我知道哪一个

此刻它会像1,2,3,4等一样上升

嗨,大家只是为了让你知道我是一个业余的诱饵你会复制和过去所以我知道你的意思谢谢

亲切的问候

保罗

.H

@interface FirstViewController : UIViewController {

    IBOutlet UILabel *time; 

    NSTimer *myticker;

    //declare baseDate
    NSDate* baseDate; 

}

-(IBAction)stop;
-(IBAction)reset;

@end
Run Code Online (Sandbox Code Playgroud)

.M

#import "FirstViewController.h"

@implementation FirstViewController

-(IBAction)start {
    [myticker invalidate];
    baseDate = [NSDate date];
    myticker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}

-(IBAction)stop;{ 

    [myticker invalidate];
    myticker = nil;
}
-(IBAction)reset;{

    time.text = @"00:00:00";
}
-(void)showActivity {
    NSTimeInterval interval = [baseDate timeIntervalSinceNow];
    NSUInteger seconds = ABS((int)interval);
    NSUInteger minutes = seconds/60;
    NSUInteger hours = minutes/60;
    time.text = …
Run Code Online (Sandbox Code Playgroud)

xcode nstimer nstimeinterval

5
推荐指数
1
解决办法
4660
查看次数

如何将NSTimeInterval值存储到NSMutableArray中?

我有一个要求,我有一个使用的视频MPMediaPlayerController.除了视频我还有两个按钮,我需要在点击按钮时捕获当前的播放时间并单独存储所有相关的点击.我可以使用返回的"currentPlaybackTime"属性获取视频的当前播放时间NSTimeInterval.但有人可以帮助我如何将所有NSTimeInterval值存储到一个NSMutableDictionary.我尝试了以下方法:

-(void)onClickOfGood {
    NSLog(@"The current playback time in good:%g",moviePlayerController.currentPlaybackTime);
    currentPlaybackTime = moviePlayerController.currentPlaybackTime;
    //NSArray *arrayContainsGoodClicks = [[NSArray alloc]initWithObjects:currentPlaybackTime, nil ];
    NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
    NSMutableArray *arrayContainsGoodClicks = [[NSMutableArray alloc]initWithObjects:goodTimeIntervals,nil ];
    NSLog(@"The total count of Array is: %i",[arrayContainsGoodClicks count]);}
Run Code Online (Sandbox Code Playgroud)

但是每次点击好按钮后我都会将阵列计数仅为1.有人可以点亮我出错的地方吗?

iphone objective-c nsmutablearray nstimeinterval ios5

5
推荐指数
1
解决办法
2858
查看次数

如何获取“当前系统时间”?

的文档SKScene -update如下: 文档

“当前系统时间”到底是什么?除了 via 之外如何获取它SKScene -update

我已经尝试过CFAbsoluteTimeGetCurrent(),但显然

返回当前系统绝对时间[,即]相对于绝对参考日期 2001 年 1 月 1 日 00:00:00 GMT 以秒为单位测量。

并且与“当前系统时间”不同,根据我的测试,“当前系统时间”的值比“当前绝对时间”小几个数量级。

time nstimeinterval sprite-kit skscene swift

5
推荐指数
1
解决办法
3290
查看次数

在Swift中添加和减去时间

我用伪代码写了一些,因为我不知道它的语法.我想知道timeLeftLabel.text在6小时结束之前剩下多少小时,分钟和秒.我最大的问题是我不知道如何加减次数.谁能帮我?

var timer = NSTimer()

func timerResults() {
    let theDate = NSDate()
    var endTime = theDate //+ 6 hours
    let timeLeft = endTime //- theDate
    timeLeftLabel.text = "\(timeLeft)"
}

@IBOutlet weak var timeLeftLabel: UILabel!
@IBAction func IBbtnUpdateTap(sender: UIButton){

timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("timerResults"), userInfo: nil, repeats: true)

}
Run Code Online (Sandbox Code Playgroud)

nstimer nstimeinterval ios swift

5
推荐指数
1
解决办法
4134
查看次数