unsigned units=NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit|NSWeekdayCalendarUnit;        NSCalendar *mycal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now=[NSDate date];
NSDateComponents *comp =[mycal components:units fromDate:now];
NSInteger month=[comp month];
NSInteger year =[comp year];
NSInteger day=[comp day];
NSCalendar *gregorian = [NSCalendar currentCalendar];
NSDateComponents *dateComps = [gregorian components:NSWeekdayCalendarUnit fromDate:now];
int daycount = [dateComps weekday] - ;
NSDate *weekdaybegin=[now addTimeInterval:-daycount***];
NSDate *weekdayend =[now addTimeInterval:(-daycount)***];
NSDateFormatter *df1=[[NSDateFormatter alloc]init];
NSLocale *mylocal=[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
[df1 setLocale:mylocal];
[df1 setDateFormat:@"YYYY-MM-d"]; now=weekdaybegin;
comp=[mycal components:units fromDate:now];
month=[comp month];
year =[comp year];
day=[comp day];
NSString *date1=[[NSString alloc]initWithFormat:@"%d-%02d-%02d",year,month,day];//所要求的周一的日期
now=weekdayend;
comp=[mycal components:units fromDate:now];
month=[comp month];
year =[comp year];
day=[comp day];
NSString *date2=[[NSString alloc]initWithFormat:@"%d-%02d-%02d",year,month,day];//所要求的周日的日期

IOS 计算本周的起至日期的更多相关文章

  1. new date() 计算本周周一日期

    new date() 计算本周周一日期 需求:计算某天的那一周周一的日期 1.new Date() date.getDay(); //获取周几 0-6 date.getTime();//获取时间戳 1 ...

  2. IOS 计算两个经纬度之间的距离

    IOS 计算两个经纬度之间的距离 一 丶 -(double)distanceBetweenOrderBy:(double) lat1 :(double) lat2 :(double) lng1 :(d ...

  3. ios 把毫秒值转换成日期 NSDate

    ios 把毫秒值转换成日期 (比较好用) 1343359790000 这是毫秒值------最佳解决方案-------------------- long long time=134335979000 ...

  4. 前端yyyy-mm-dd格式 计算一段工作日后,日期

    //计算一段工作日后,日期getWorkday(dat, itervalByDay) { function formatTen(f) { if (parseInt(f, 10) < 10) { ...

  5. iOS学习笔记37-时间和日期计算

    一.时间和日期计算 我们在应用开发中,时常须要和时间打交道,比方获取当前时间,获取两个时间点相隔的时间等等,在iOS开发中与时间相关的类有例如以下几个: 1. NSDate:表示一个绝对的时间点 2. ...

  6. iOS 计算两个日期之间的天数问题

    //获取当前时间若干年.月.日之后的时间 + (NSDate *)dateWithFromDate:(NSDate *)date years:(NSInteger)years months:(NSIn ...

  7. iOS 计算 日期 距离 当前 系统的日期 相差 多少

    #pragma mark - 时间计算函数 - (NSTimeInterval)intervalSinceNow:(NSString *) theDate { NSDateFormatter * da ...

  8. 用c/c++混合编程方式为ios/android实现一个自绘日期选择控件(一)

    本文为原创,如有转载,请注明出处:http://www.cnblogs.com/jackybu 前言 章节: 1.需求描述以及c/c++实现日期和月历的基本操作 2.ios实现自绘日期选择控件 3.a ...

  9. iOS 和Android中的基本日期处理

    提到日期处理,主要有2个参数,一个是所在的时区,一个是所用的日历方法. 主要涉及2大类问题,一类是日期类型和字符串之间的转化,另一类是日期的计算问题.ios和android都提供了相应的类来处理问题. ...

随机推荐

  1. @Resource或者@Autowired作用/Spring中@Autowired注解、@Resource注解的区别

    @Resource或者@Autowired作用不用写set get就能注入,当然,前提是你已经开启了注解功能. spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定 ...

  2. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!问题解决

    用mac终端ssh连接Linux服务器,提示以下错误: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ WARNING: RE ...

  3. WCF实现客户端和服务端

    service side 1.定义ServiceContract: 2.new a ServiceHost 3. add endpoint using System.ServiceModel; nam ...

  4. Django中的 动态URL配置

    举个例子,一家在线书店会为每一本书提供一个URL,如:/books/243/./books/81196/. 让我们创建第三个视图来显示当前时间和加上时间偏差量的时间,设计是这样的: /time/plu ...

  5. redis conf 详解

    2.8配置 # Redis configuration file example # Note on units: when memory size is needed, it is possible ...

  6. 可能是最通俗易懂的 Java 位操作运算讲解

    https://blog.csdn.net/briblue/article/details/70296326

  7. Java - web.xml文件中可以配置哪些内容?

    web.xml用于配置Web应用的相关信息,如:监听器(listener).过滤器(filter).Servlet.相关参数.会话超时时间.安全验证方式.错误页面等,下面是一些开发中常见的配置: ①配 ...

  8. linux学习笔记24---命令grep

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是global search regular expression(RE) and ...

  9. MySQL5.7的配置文件

    5.7  /etc/mysql/mysql.conf.d/mysqld.cnf 5.6  /etc/my.cnf  或  /etc/mysql/my.cnf

  10. 数据库设计(七)第三范式(3NF)

    In our last tutorial, we learned about the second normal form and even normalized our Score table in ...