Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDateFormatter Question

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

like image 473
h4wkeye Avatar asked Apr 15 '11 08:04

h4wkeye


2 Answers

Looks like nobody has answered you about milliseconds... use "S" in your format string, like this:

[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
like image 151
Alan Avatar answered Nov 04 '22 19:11

Alan


You set one more property for dateFormatter like this

[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"]; 
like image 31
EXC_BAD_ACCESS Avatar answered Nov 04 '22 19:11

EXC_BAD_ACCESS