Monday, March 1, 2010

NSDate to NSString

Az NSDateFormatter segitsegevel igy:

NSDate *now = [NSDate date];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateStyle:NSDateFormatterFullStyle];

NSString *s = [dateFormat stringFromDate:now];

[dateFormat release];

Persze ha a setDateStyle helyett a setDateFormat-ot hasznajuk akkor a Date Formatter lehet sokfele, peldaul:
"MM.dd.yyyy. hh:mm" > "03.01.2010"
"MM/dd/yyyy hh:mma" > "03/01/2010 04:20PM"
Vagy a setDateStyle-nal maradva az NSDateFormatterStyle-bol hasznalhatjuk barmelyiket.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.