- (NSString *)todayDate
{
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:today];
return [NSString stringWithFormat:@"%.4d-%.2d-%.2d",[components year],[components month],[components day]];
}
- (NSString *)currTime
{
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
NSUInteger unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:today];
return [NSString stringWithFormat:@"%.2d:%.2d",[components hour],[components minute]];
}
沒有留言:
張貼留言