Kishore Reddy
Kishore Reddy

Reputation: 926

How do I format a date to a string including milliseconds?

NSString *nameToSave = word;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *fromDateString=[dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];

nameToSave = [word stringByAppendingString:fromDateString];
nameToSave = [nameToSave stringByAppendingString:@".txt"];
NSLog(@"Server notes name .............>>>>>>!!!! %@",nameToSave);

for saving filenames i am using dateformatter, my problem is in the above code word is same for two files and it is run within one second then two file names are same. So the files are overriding.., i think with use of milliseconds i can solve my problem, But i don't know how to get current time in milliseconds. [ seconds/1000 or any arithmetic operations is not helpful for me..., because after applying arithmetic operation also we get same name]

Upvotes: 3

Views: 3365

Answers (2)

Martin R
Martin R

Reputation: 539685

You can set a date format like

[dateFormatter setDateFormat:@"yyyy-MM-dd-HH:mm:ss:SSS"];

"SSS" is for milliseconds.

Upvotes: 9

nsgulliver
nsgulliver

Reputation: 12671

just do like this [[NSDate date] timeIntervalSince1970];

Upvotes: 5

Related Questions