iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
来源:互联网 发布:心动网络密保产品 编辑:程序博客网 时间:2024/05/19 14:52
//获取系统当前时间
- (NSString*)get_system_today_time
{
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:kCFDateFormatterMediumStyle];
[formatter setTimeStyle:kCFDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd-hh-mm-ss"];
NSString *string_time = [formatterstringFromDate:date];
NSArray *time = [string_timecomponentsSeparatedByString:@"-"];
int value_year = [[timeobjectAtIndex:0]intValue];
int value_month = [[timeobjectAtIndex:1]intValue];
int value_day = [[timeobjectAtIndex:2]intValue];
int value_hour = [[timeobjectAtIndex:3]intValue];
int value_minute = [[timeobjectAtIndex:4]intValue];
int value_second = [[timeobjectAtIndex:5]intValue];
[formatter setDateFormat:@"EEEE"];
NSString *week_day = [formatter stringFromDate:date];
[formatter release];
NSString *system_time = [[NSStringalloc]initWithFormat:@"{\"year\":\"%d\",\"month\":\"%d\",\"day\":\"%d\",\"hour\":\"%d\",\"minute\":\"%d\",\"second\":\"%d\",\"week_day\":\"%@\"}",value_year,value_month,value_day,value_hour,value_minute,value_second,week_day];
NSLog(@"\nsystem time is %@",system_time);
return [system_timeautorelease];
}
----------------------------------------------------------------------------
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comps;
// 年月日获得
comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:date];
NSInteger year = [comps year];
NSInteger month = [comps month];
NSInteger day = [comps day];
NSLog(@"year: %d month: %d, day: %d", year, month, day);
//当前的时分秒获得
comps = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:date];
NSInteger hour = [comps hour];
NSInteger minute = [comps minute];
NSInteger second = [comps second];
NSLog(@"hour: %d minute: %d second: %d", hour, minute, second);
// 周几和星期几获得
comps = [calendar components:(NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit)
fromDate:date];
NSInteger week = [comps week]; // 今年的第几周
NSInteger weekday = [comps weekday]; // 星期几(注意,周日是“1”,周一是“2”。。。。)
NSInteger weekdayOrdinal = [comps weekdayOrdinal]; // 这个月的第几周
NSLog(@"week: %d weekday: %d weekday ordinal: %d", week, weekday, weekdayOrdinal);
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- phone开发 获取系统时间 星期 年 月 日 时 分 秒
- iPhone开发--NSData年、月、星期、日、时、分、秒和毫秒获取及NSDataToNSString方法
- iOS 获取指定日期的时间(年、月、日、星期、时、分、秒等)
- javascript获取当前时间(年-月-日 时:分:秒)
- js 获取时间:年 月 日 时 分 秒
- 获取当前时间的年、月、日、时、分、秒
- 获取当前时间的年、月、日、时、分、秒
- js操作时间(年-月-日 时-分-秒 星期几)
- 如何获取年、月、日、时、分、秒、星期几等
- ios 获取日期(年、月、日、星期、时、分、秒)
- NSData年、月、星期、日、时、分、秒
- 1-使用系统对象 打印 年 月 日 时 分 秒 星期
- 获取年、月、日、时、分、秒
- Sql Server 2005 Express数据库导入导出功能的实现
- linux more命令
- iOS开发之core location
- 测测你的英语词汇量有多少
- hdu 2425——Hiking Trip(BFS)
- iPhone开发 获取系统时间 星期 年 月 日 时 分 秒
- 使用败者树对k段归并段进行k-路平衡归并
- jqgrid 排序,获取当前页数
- Windows XP 开机启动自动打开文件夹至Search Enhancement Pack的问题
- Ubuntu git 安装和使用
- (Qt)深受QByteArray的陷害
- CoreAnimation
- datagridview 某行不跟随排序 问题解决
- 利用Storyboard实现复杂项目