2

まず最初に、私を助けてくれてありがとうと言いたいです。

Xcodeを使用してラベルに日付を作成する方法を知りたいのですが、日付はiPhoneのように同じ日付に従います。

ありがとう

4

4 に答える 4

5

これが1つの簡単なアプローチです

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//uncomment to get the time only
//[formatter setDateFormat:@"hh:mm a"];
//[formatter setDateFormat:@"MMM dd, YYYY"];
[formatter setDateStyle:NSDateFormatterMediumStyle];


//get the date today
NSString *dateToday = [formatter stringFromDate:[NSDate date]];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 20.0f)];
[label setText:dateToday];
[formatter release];

//then add to a view
于 2011-05-04T16:49:37.960 に答える
1

日付は、以下のようにフォーマットしてラベルに設定できます。

NSDate *today = [NSDate date];
NSDateFormatter *dformat = [[NSDateFormatter alloc] init];
[dformat setDateFormat:@"dd:MM:YYYY"];
myLabel.text = [dformat stringFromDate:today];
于 2016-07-30T08:00:13.143 に答える
1

テキスト日付の作成は簡単ですが、実際の問題は、日付テキストを作成するデータ ソースは何かということです。

于 2011-05-04T16:44:30.657 に答える