如何在iOS中采用日期并提取日期? [英] How do I take a date and extract the day in iOS"
本文介绍了如何在iOS中采用日期并提取日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个webservice返回以下格式的日期:
I have a webservice that returns the date in this format:
2013-04-14
我如何知道这对应于哪一天?
How do i figure out what day this corresponds to?
推荐答案
获取工作日的另一种方法可以是:
An alternate method for getting the weekday can be:
NSString *myDateString = @"2013-04-14";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormatter dateFromString:myDateString];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
NSInteger weekday = [components weekday];
NSString *weekdayName = [dateFormatter weekdaySymbols][weekday - 1];
NSLog(@"%@ is a %@", myDateString, weekdayName);
这篇关于如何在iOS中采用日期并提取日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文