iphone - 使用自定义格式访问当前系统日期

标签 iphone objective-c ios ios5 nsdate

我将使用哪种方法打印 (MM-DD-YYYY) 格式的日期?对于 Ex 03-26-2012

我一直在尝试这段代码,但这是给了我 2012 年 3 月 26 日

NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterShortStyle];    

    NSString *currentTime = [dateFormatter stringFromDate:today];
    [dateFormatter release];
    NSLog(@"format:%@",currentTime);

我可以只访问当前日期的日期和月份吗??

最佳答案

NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM-dd-yyyy"];   

NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter release];
NSLog(@"format:%@",currentTime);

关于iphone - 使用自定义格式访问当前系统日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9873010/

相关文章:

ios - 在 Twitter App IOS 上打开链接

ios - 如果无法播放,在 UIWebView 中隐藏 HTML5 视频

ios - 使用来自原始 PCM 流的 CMSampleTimingInfo、CMSampleBuffer 和 AudioBufferList

ios - 仅在纵向模式下强制 UINavigationController

ios - 使用 Swift 从 xib/nib 实例化 UIView

ios - 修改覆盖属性 willSet get/set 的值

iphone - 带有 ios5 的 Restkit 和 three20

iOS App Development - 应用内电子邮件订阅表格的规则?

iphone - 使用 iOS 中的 post 方法通过 php Web 服务调用将注册 View Controller 文本值保存在服务器上

ios - 如何从第二个 View Controller 添加标签栏 Controller