NSDateFormatter问题

h4w*_*eye 11 iphone time xcode objective-c nsdateformatter

我使用以下代码来获取当前时间..

NSDate *myDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0200"]];

// Set date style:
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];

NSString *GMTDateString = [dateFormatter stringFromDate: myDate];
Run Code Online (Sandbox Code Playgroud)

我的问题是:我希望时间用HH:MM:SS :(如果可能的话,毫秒)

当我运行项目时,它显示日期和正确的时间,但它也打印"MESZ",我认为这意味着我的语言中欧系统时间.

我如何摆脱MESZ并以毫秒为单位打印时间?

任何帮助表示赞赏

提前致谢

h4wkeye

编辑:

我现在需要的只是如何打印毫秒的建议!谢谢你所有有用的答案

Ala*_*lan 72

看起来没有人回答你关于毫秒...在你的格式字符串中使用"S",如下所示:

[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
Run Code Online (Sandbox Code Playgroud)


Rob*_*bin -2

将 NSDateFormatter 的“setDateFormat:”与您的自定义属性一起使用,如何使用它的说明可以在这里找到:http ://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/Articles/ dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1