objective-c - 在 xcode 标签中创建日期

标签 objective-c swift xcode date label

首先,我想提前感谢您对我的帮助。

我想知道如何使用 Xcode 在标签上创建日期, 并且日期将遵循与 iphone 中相同的日期。

谢谢

最佳答案

这是一种简单的方法

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

关于objective-c - 在 xcode 标签中创建日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5886807/

相关文章:

iOS Swift - 减少功能

JSONEncoder.encode 产生 : Thread 1: EXC_BAD_ACCESS in case of inheritance

iPhone RestKit 加载 NSManagedObject 而不是 NSManagedObject+(ActiveRecord)

objective-c - cocoa 、XCode、Objective-C

iphone - 在二维数组中使用 NSPredicate

swift - URLRequest 相等性不包括 httpBody

ios - 如何跟踪使用 NSIndexPath 选择的单元格?

ios - 如何更改 xcdatamodel 中的属性类型?

ios - GoogleMaps SDK 类未声明的类型或未解析的标识符

objective-c - 如何在给定 CGPoint 的情况下获取 UIView?