2011年1月31日

[iPhone]NSDate和NSString的互相轉換

NSDate轉換為NSString

NSDateFormatter *date_formatter = [[[NSDateFormatter alloc]init] autorelease];
[date_formatter setDateFormat:@"YYYY/MM/dd hh:mm"];
NSString *date = [[date_formatter stringFromDate:[NSDate date]]];


NSString轉換為NSDate

NSDateFormatter *date_formatter = [[[NSDateFormatter alloc]init] autorelease];
[date_formatter setDateFormat:@"YYYY/MM/dd hh:mm"];
NSDate *date = [date_formatter dateFromString:@"2010/01/01 12:12"];

沒有留言: