2011-11-13 7 views
0

週の特定の日にカウントダウンをコーディングしようとしています。 現在の平日と残りの秒を水曜日に表示します。特定の曜日に秒単位でカウントダウンする

私は最初の部分をコーディングすることができますが、半日後に解決策を探しても、2番目の部分は処理できません。 NSDateとNSDateFormatterクラスの両方で

- (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]]; 
} 

答えて

0

見ては、彼らはこの種のものを行うためのルーチンと豊富です:

は、これは私が今持っているものです。

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ドキュメントを見ることができるはずです。

+0

ありがとう、私はすでにそれをしました。私の問題は、私は翌年の新年にカウントダウンすることができるということです。しかし、週の特定の日にカウントダウンしたいので、週の任意の日から、私は失われています。 –

関連する問題