NSDateFormatter问题 [英] NSDateFormatter Question

查看:66
本文介绍了NSDateFormatter问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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];

我的问题是: 我想要HH:MM:SS :(如果可能的话,以毫秒为单位)

My problem is : I want the time in HH:MM:SS:(milliseconds if possible)

当我运行项目时,它会显示日期和正确的时间,但还会打印"MESZ",我认为这是用我的语言表示的中欧系统时间.

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.

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

How od i get rid of MESZ and print the time with miliseconds?

感谢您的帮助

预先感谢

h4wkeye

我现在所需要的只是关于如何打印毫秒的建议!感谢您的所有有帮助的答案

All i need now is an advice on how to print the milliseconds as well! Thanks for all your helpful answers

推荐答案

在自定义属性中使用NSDateFormatter的"setDateFormat:",有关如何使用它的说明可在此处找到:

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

这篇关于NSDateFormatter问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆