如何更改此代码,使其具有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) 的文档SKScene -update如下:

“当前系统时间”到底是什么?除了 via 之外如何获取它SKScene -update?
我已经尝试过CFAbsoluteTimeGetCurrent(),但显然
返回当前系统绝对时间[,即]相对于绝对参考日期 2001 年 1 月 1 日 00:00:00 GMT 以秒为单位测量。
并且与“当前系统时间”不同,根据我的测试,“当前系统时间”的值比“当前绝对时间”小几个数量级。
我用伪代码写了一些,因为我不知道它的语法.我想知道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) 我需要从上次设备启动时获取NSTimeInterval值.我发现CACurrentMediaTime()适合这个任务,但在我的应用程序中我没有使用Core Animation,我不认为这是包含这个框架只是为了获得这个功能的最佳方式.有没有另一种方法可以在最后一次启动后的几秒钟内获得更优雅的方式?
我想比较两个日期之间的差异,但是使用下面的代码我收到错误"[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) 我试着用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) 我不明白这个例子来自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)
谢谢你的帮助
我的问题是我希望有一些方法来表示时间(没有日期),比如我的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替换日期部分仍然很高兴有一个独立于日期的时间表示.
给定表示一段时间的NSTimeInterval,如何创建一个人类可读的字符串,以一种尊重i18N的方式表达该时间段?
例如,如果NSTimeInterval等于10823.23435秒,那么将一些合理的方法呈现为美国人的字符串可能是:
(即你在秒表上看到的东西.)
据推测,其他区域设置可能使用不同的渲染.
我知道NSDateFormatter和NSNumberFormatter,但我不清楚是否或如何使用其中一个来解决这个问题.
我也知道FormatterKit,但这只是相对时间段(例如,"3分钟前").我正在寻找绝对的时间段.
制作我自己的特定于语言环境的解决方案是微不足道的,但是这个问题已经解决了吗?
谢谢.
我需要在应用程序的数据库中存储一个时间间隔,偶尔会添加NSDate.问题是,我不知道要为它选择什么数据类型.有些人建议存储NSTimeInterval,但是当用户的时区发生变化时会导致计算错误吗?也许最好存储NSDateComponents(作为"可转换"数据类型)还是有另一种更好的方法来存储它?
nstimeinterval ×10
ios ×6
swift ×4
iphone ×2
nsdate ×2
nstimer ×2
objective-c ×2
cllocation ×1
cocoa ×1
core-data ×1
ios5 ×1
nscalendar ×1
nsstring ×1
skscene ×1
sprite-kit ×1
time ×1
xcode ×1
xcode4 ×1