//中国时区时间
[NSTimeZone setDefaultTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSLog(@"%@",[dateFormatter stringFromDate:date]);
//显示星期几
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"]];
dateFormatter.dateFormat = @"yyyy-MM-dd EEEE";
//得到当前的日期
NSDate *date = [NSDate date];
NSLog(@"date:%@",date);
//得到(24 * 60 * 60)即24小时之前的日期,dateWithTimeIntervalSinceNow:
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow: -(24 * 60 * 60)];
NSLog(@"yesterday:%@",yesterday);
NSDateFormatter *formatter =[[[NSDateFormatter alloc] init] autorelease];
NSDate *date = [NSDate date];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
NSInteger unitFlags = NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSWeekdayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
//int week=0;
comps = [calendar components:unitFlags fromDate:date];
int week = [comps weekday];
int year=[comps year];
int month = [comps month];
int day = [comps day];
//[formatter setDateStyle:NSDateFormatterMediumStyle];
//This sets the label with the updated time.
int hour = [comps hour];
int min = [comps minute];
int sec = [comps second];
NSLog(@"week%d",week);
NSLog(@"year%d",year);
NSLog(@"month%d",month);
NSLog(@"day%d",day);
NSLog(@"hour%d",hour);
NSLog(@"min%d",min);
NSLog(@"sec%d",sec);
//得到毫秒
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
//[dateFormatter setDateFormat:@"hh:mm:ss"]
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSLog(@"Date%@", [dateFormatter stringFromDate:[NSDate date]]);
[dateFormatter release];
/**
* 取最近七天的时间
**/
- (void)receiveCurrentTime:(NSNotification*)notify
{
NSDictionary *dic = [notify userInfo];
NSDate *currentDate = [dic objectForKey:currentTimeResult];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"]];
dateFormatter.dateFormat = @"yyyy-MM-dd EEEE";
NSMutableArray *dateslist = [[NSMutableArray alloc] init];
for (int i = 0; i < 7; i++) {
NSDate *newDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:([currentDate timeIntervalSinceReferenceDate] + 24*3600*i)];
[dateslist addObject:newDate];
NSString *str = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:newDate]];
[_dateList addObject:str];
}
NSString *defaultDateStr = [self transToSendDateString:currentDate];
_requestSeat.dateStr = defaultDateStr;
_dates = dateslist;
}
NSDate 年 月 日 星期 毫秒数
猜你喜欢
转载自lizhuang.iteye.com/blog/1850355
今日推荐
周排行