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];
我的问题是: 我想要的时间为 HH:MM:SS:(如果可能的话,毫秒)
当我运行该项目时,它会显示日期和正确的时间,但它还会打印“MESZ”,我认为这意味着用我的语言表示中欧系统时间。
我如何摆脱 MESZ 并打印以毫秒为单位的时间?
任何帮助
提前感谢
h4wkeye
编辑:
我现在需要的只是关于如何打印毫秒的建议!感谢您提供的所有有用的答案
i am using the following code to get the current time..
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];
My problem is :
I want the time in HH:MM:SS:(milliseconds if possible)
When i run the project, it displays the date and the right time but it also prints "MESZ" which i assume means Middle European System time in My language.
How od i get rid of MESZ and print the time with miliseconds?
Any help is appreciated
thanks in advance
h4wkeye
EDIT :
All i need now is an advice on how to print the milliseconds as well! Thanks for all your helpful answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来没有人回答你有关毫秒的问题...在格式字符串中使用“S”,如下所示:
Looks like nobody has answered you about milliseconds... use "S" in your format string, like this:
您可以像这样为 dateFormatter 设置另一个属性
You set one more property for dateFormatter like this
将 NSDateFormatter 的“setDateFormat:”与您的自定义属性一起使用,如何使用它的说明可以在这里找到:http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/文章/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
Use the "setDateFormat:" of NSDateFormatter with your custom attributes, an explanation of how to use it can be found here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1