2010-06-09 102 views

回答

6

此代碼將得到你需要設置標籤的字符串:

NSDate *today = [NSDate date]; 
NSDateFormatter *weekdayFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
[formatter setDateFormat: @"d MMMM yyyy"]; 
[weekdayFormatter setDateFormat: @"EEEE"]; 
NSString *formattedDate = [formatter stringFromDate: today]; 
NSString *weekday = [weekdayFormatter stringFromDate: today]; 

格式化通過這個標準來控制的日期:Unicode Date Formats

4
[label1 setText:@"Tuesday"]; 
[label2 setText:@"2 June 2010"]; 

或者您是否需要不同的東西?

+1

+1:只有他問了如何得到值:'NSString * str = [label1 t ext]':p – v1Axvw 2011-02-05 17:00:04

2

你好,你可以得到星期和日期從這個代碼 並在這裏平日給你一天例如:星期一,星期二重新

NSDate *today = [NSDate date]; 
NSDateFormatter *weekdayFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; 
[formatter setDateFormat: @"d MMMM yyyy"]; 
[weekdayFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; 
[weekdayFormatter setDateFormat: @"EEEE"]; 
NSString *formattedDate = [formatter stringFromDate: today]; 
NSString *weekday = [weekdayFormatter stringFromDate: today];