标签: nstimeinterval

使用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
查看次数

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

的文档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
查看次数

如何从上次启动获取NSTimeInterval值

我需要从上次设备启动时获取NSTimeInterval值.我发现CACurrentMediaTime()适合这个任务,但在我的应用程序中我没有使用Core Animation,我不认为这是包含这个框架只是为了获得这个功能的最佳方式.有没有另一种方法可以在最后一次启动后的几秒钟内获得更优雅的方式?

iphone nstimeinterval ios

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

[NSCFString timeIntervalSinceReferenceDate]:发送到实例的无法识别的选择器

我想比较两个日期之间的差异,但是使用下面的代码我收到错误"[NSCFString timeIntervalSinceReferenceDate]:无法识别的选择器发送到实例." 代码有什么问题?

NSDate *dateAdded=[eventDictionary objectForKey:@"dateAdded"];
NSDate *validUntilDate=[eventDictionary objectForKey:@"validUntilDate"];
NSDateComponents *sometimeAgo = [[NSCalendar currentCalendar] components:(NSSecondCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:dateAdded  toDate:validUntilDate  options:0]; 
Run Code Online (Sandbox Code Playgroud)

nsdate nscalendar nstimeinterval ios

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

将NSString转换为NSTimeInterval

我试着用NSTimeInterval进行倒计时.但我希望能够在不发布每次更新的情况下更改间隔.所以我尝试从我的网站导入Timeinterval.我已经将NSTimeInterval的数字存储在NSString中,并且现在想要将它们转换为NSTimeInterval,以便将其实现为倒计时代码...

......但它不起作用.有任何想法吗?

label.text = string;
double timeInterval = [label.text doubleValue];
NSTimeInterval intervalForTimer = timeInterval;
destinationDate = [[NSDate dateWithTimeIntervalSince1970:intervalForTimer] retain];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

编辑:

- (void)updateLabel {

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
    [dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components minute], 'm', [components second], 's']];

}
Run Code Online (Sandbox Code Playgroud)

我的新代码看起来像这样:

    NSLog(@"Downloaded …
Run Code Online (Sandbox Code Playgroud)

iphone nsstring nstimeinterval xcode4 ios5

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

使用负值计算'timeIntervalSinceNow'(CLLocation示例)?

我不明白这个例子来自doc:timeIntervalSinceNow方法应该显示一个正值,但是我们怎么能达到代码中提到的"5"?(我认为它或者更多或更少,或者-10,-20,-30等...但是我们怎样才能获得正值,例如5?):

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    // test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

objective-c nstimeinterval cllocation

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

NSDate但没有NSTime,如何转换字符串表示的时间(没有日期)

我的问题是我希望有一些方法来表示时间(没有日期),比如我的iOS应用程序中的时间.从REST api我得到像"13:12:11"这样的字符串,它显示了时间发生的事情,我已经习惯NSDateFormatter将NSStrings转换为NSDates但据我所知它不接受日期格式只有像HH:mm:ss[EDIT] 这样的时间组件:你可以,见下文]

所以我的问题是1-是NSTimeInterval(而不是NSDate)我应该用什么来存储时间?
2-如何将"03:04:05"转换为来自其中一个内置框架的objective-c对象.

编辑:您可以使用像"HH:mm:ss"这样的格式,它只是用2000-01-01替换日期部分仍然很高兴有一个独立于日期的时间表示.

nsdate nsdateformatter nstimeinterval ios

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

如何正确格式化NSTimeInterval作为时间段,尊重i18n?

给定表示一段时间的NSTimeInterval,如何创建一个人类可读的字符串,以一种尊重i18N的方式表达该时间段?

例如,如果NSTimeInterval等于10823.23435秒,那么将一些合理的方法呈现为美国人的字符串可能是:

  • 3:23
  • 3小时23秒
  • 等等

(即你在秒表上看到的东西.)

据推测,其他区域设置可能使用不同的渲染.

我知道NSDateFormatter和NSNumberFormatter,但我不清楚是否或如何使用其中一个来解决这个问题.

我也知道FormatterKit,但这只是相对时间段(例如,"3分钟前").我正在寻找绝对的时间段.

制作我自己的特定于语言环境的解决方案是微不足道的,但是这个问题已经解决了吗?

谢谢.

cocoa objective-c nstimeinterval ios swift

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

在Core Data中存储时间间隔的正确方法是什么?

我需要在应用程序的数据库中存储一个时间间隔,偶尔会添加NSDate.问题是,我不知道要为它选择什么数据类型.有些人建议存储NSTimeInterval,但是当用户的时区发生变化时会导致计算错误吗?也许最好存储NSDateComponents(作为"可转换"数据类型)还是有另一种更好的方法来存储它?

core-data nsdatecomponents nstimeinterval ios swift

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