Objective c 按秒倒计时到特定的工作日
我正在尝试编码一周中某一天的倒计时。 我想显示当前工作日以及到周三的剩余秒数 我能够编写第一部分的代码,但即使在半天的解决方案搜索之后,我也无法处理第二部分 这就是我现在拥有的:Objective c 按秒倒计时到特定的工作日,objective-c,ios,cocoa-touch,time,nsdate,Objective C,Ios,Cocoa Touch,Time,Nsdate,我正在尝试编码一周中某一天的倒计时。 我想显示当前工作日以及到周三的剩余秒数 我能够编写第一部分的代码,但即使在半天的解决方案搜索之后,我也无法处理第二部分 这就是我现在拥有的: - (void)viewDidLoad { [countdownLabel setFont:[UIFont fontWithName:@"Helvetica" size:128.0]]; countdownLabel.text = @"What day ist it?"; [super view
- (void)viewDidLoad {
[countdownLabel setFont:[UIFont fontWithName:@"Helvetica" size:128.0]];
countdownLabel.text = @"What day ist it?";
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[super dealloc];
}
-(void)updateLabel {
NSDateFormatter* theDateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[theDateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[theDateFormatter setDateFormat:@"EEEE"];
countdownLabel.text = [theDateFormatter stringFromDate:[NSDate date]];
}
看看NSDate和NSDateFormatter类,它们都有丰富的例程来完成这类工作
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSDateFormatter * df = [NSDateFormatter dateFormatFromTemplate:@"yyyy-MM-dd-HH:mm" options:0 locale:usLocale];
NSDate * newyear = [df dateFromString:@"2012-01-01-00:00"];
NSTimeInterval seconds = [newyear timeIntervalSinceDate:[NSDate date]];
我还没有尝试编译上面的内容,但它应该会给你足够的时间。您应该能够查看NSDateFormatter文档,轻松找到一周中的哪一天。谢谢,我已经这样做了。我的问题是,我将能够编码到明年的新年倒计时。但是当我想倒数到一周中的某一天,从一周中的任何一天开始,我就迷路了。