---
title: "[ios]NSDateFormatter 获取第几周"
author: "119568242"
date: "2013-04-17T00:43:16Z"
tags: []
categories: ["移动开发"]
slug: "ios-nsdateformatter"
draft: false
lastmod: "2013-04-17T16:47:19Z"
id: 1848574
url: "https://poolo.iteye.com/blog/1848574"
---

```c
NSCalendar* calendar =[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
calendar.firstWeekday =2;
df.calendar = calendar;

date =[NSDate dateWithString:@"2012-01-01 12:00:00 +0000"];NSLog(@"%@ -> %@", date,[df stringFromDate:date]);

date =[NSDate dateWithString:@"2012-01-02 12:00:00 +0000"];NSLog(@"%@ -> %@", date,[df stringFromDate:date]);

```

```c
2012-02-2411:31:27.878Test[2546:15203]2012-02-2610:20:42+0000->02Sun2012092012-02-2411:31:27.880Test[2546:15203]2012-02-2610:20:42+0000->02Sun201209
```

 

```c
calendar.firstWeekday =2;每周的第一天从星期几开始算 1 星期日 2星期一
```

 

参考：http://stackoverflow.com/questions/9360474/nsdateformatter-week-of-year-and-first-weekday