How do I get the day of the week as a string?
13 Answers
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];  
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
outputs current day of week as a string in locale dependent on current regional settings.
To get just a week day number you must use NSCalendar class:
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *comps = [gregorian components:NSWeekdayCalendarUnit fromDate:[NSDate date]];
int weekday = [comps weekday];
- 170,431
 - 36
 - 387
 - 313
 
- 
                    14And to get the names of all weekdays you can use `[dateFormatter weekdaySymbols]` (and similar), which returns an NSArray of NSStrings starting with Sunday at index 0. – beetstra Nov 09 '11 at 12:18
 - 
                    Okay, how do I get day of week starting with Monday, not with Sunday? – Vladimir Stazhilov Mar 21 '12 at 16:51
 - 
                    2@VovaStajilov probably this question:http://stackoverflow.com/questions/1106943/nscalendar-first-day-of-week will help. Basically you need to set calendar's first weekDay to be monday ([calendar setFirstWeekday:2]) – Vladimir Mar 21 '12 at 17:10
 - 
                    1the first NSLog returns 475221968 which is a unrealistic, huge number for day of week. . . – coolcool1994 Jun 02 '13 at 11:49
 - 
                    Ok, @Vladimir, I set `[gregorian setFirstWeekday:2];` and for **Monday 01/06/2015** I receive 2 (`[components weekday]`). Why? - I find answer [here](http://stackoverflow.com/questions/16875420/nscalendar-why-does-setting-the-firstweekday-doesnt-effect-calculation-outcome) – new2ios Jun 08 '15 at 11:06
 - 
                    Just a note, `weekday` returns an `NSInteger` (an `unsigned long`) and not an int, which could account for the `475221968` number. – PLJNS Jul 01 '15 at 17:41
 - 
                    As of iOS 8, `NSGregorianCalendar ` is deprecated in favor of `NSCalendarIdentifierGregorian`. Same is true of `NSWeekdayCalendarUnit ` with `NSCalendarUnitWeekday` – Tom Howard Apr 13 '16 at 20:39
 
Just use these three lines:
CFAbsoluteTime at = CFAbsoluteTimeGetCurrent();
CFTimeZoneRef tz = CFTimeZoneCopySystem();
SInt32 WeekdayNumber = CFAbsoluteTimeGetDayOfWeek(at, tz);
- 9,564
 - 146
 - 81
 - 122
 
- 339
 - 4
 - 13
 
- 
                    3I like it but that would almost count as obfuscation to some new developers (which may be an evil bonus) ;) – David Rönnqvist Sep 12 '13 at 16:17
 - 
                    3CFAbsoluteTimeGetDayOfWeek is deprecated in iOS 8. Is there an alternate way using CFCalendar? – Jordan Smith Sep 28 '14 at 10:45
 
Many of the answers here are deprecated. This works as of iOS 8.4 and gives you the day of the week as a string and as a number.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
NSLog(@"The day of the week: %@", [dateFormatter stringFromDate:[NSDate date]]);
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *comps = [gregorian components:NSCalendarUnitWeekday fromDate:[NSDate date]];
int weekday = [comps weekday];
NSLog(@"The week day number: %d", weekday);
- 153
 - 1
 - 6
 
- 
                    1As a side note – Because the `weekday` component of `NSCalendar` is an `NSInteger`, you will need to cast `[comps weekday]` to an `int`, if you need to, or else it will show a warning regarding this. – mylogon Feb 22 '16 at 11:35
 
Here's how you do it in Swift 3, and get a localised day name…
let dayNumber = Calendar.current.component(.weekday, from: Date()) // 1 - 7
let dayName = DateFormatter().weekdaySymbols[dayNumber - 1]
- 50,474
 - 16
 - 129
 - 160
 
-(void)getdate {
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyy-MM-dd"];
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"MMM dd, yyyy HH:mm"];
    NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
    [timeFormat setDateFormat:@"HH:mm:ss"];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;
    [dateFormatter setDateFormat:@"EEEE"];
    NSDate *now = [[NSDate alloc] init];
    NSString *dateString = [format stringFromDate:now];
    NSString *theDate = [dateFormat stringFromDate:now];
    NSString *theTime = [timeFormat stringFromDate:now];
    NSString *week = [dateFormatter stringFromDate:now];
    NSLog(@"\n"
          "theDate: |%@| \n"
          "theTime: |%@| \n"
          "Now: |%@| \n"
          "Week: |%@| \n"
         , theDate, theTime,dateString,week); 
}
- 6,900
 - 6
 - 40
 - 60
 
- 673
 - 1
 - 10
 - 14
 
I needed a simple (Gregorian) day of the week index, where 0=Sunday and 6=Saturday to be used in pattern match algorithms. From there it is a simple matter of looking up the day name from an array using the index. Here is what I came up with that doesn't require date formatters, or NSCalendar or date component manipulation:
+(long)dayOfWeek:(NSDate *)anyDate {
    //calculate number of days since reference date jan 1, 01
    NSTimeInterval utcoffset = [[NSTimeZone localTimeZone] secondsFromGMT];
    NSTimeInterval interval = ([anyDate timeIntervalSinceReferenceDate]+utcoffset)/(60.0*60.0*24.0);
    //mod 7 the number of days to identify day index
    long dayix=((long)interval+8) % 7;
    return dayix;
}
- 2,203
 - 1
 - 21
 - 18
 
I think this topic is really useful, so I post some code Swift 2.1 compatible.
extension NSDate {
    static func getBeautyToday() -> String {
       let now = NSDate()
       let dateFormatter = NSDateFormatter()
       dateFormatter.dateFormat = "EEEE',' dd MMMM"
       return dateFormatter.stringFromDate(now)
    }
}
Anywhere you can call:
let today = NSDate.getBeautyToday()
print(today) ---> "Monday, 14 December"
Swift 3.0
As @delta2flat suggested, I update answer giving user the ability to specify custom format.
extension NSDate {
    static func getBeautyToday(format: String = "EEEE',' dd MMMM") -> String {
        let now = Date()
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = format
        return dateFormatter.string(from: now)
    }
}
- 21,000
 - 15
 - 120
 - 146
 
- 
                    is this localized? what if your intended country wanted to use "14 December, Monday" or "14 Monday December"? it should be handled therein – Corbin Miller Mar 22 '17 at 18:08
 - 
                    Hi @delta2flat. Yes, format is localized. Btw I've updated answer: now user can specify custom format – Luca Davanzo Mar 23 '17 at 09:06
 - 
                    Great - I've found that Objective-C / Cocoa Touch is pretty powerful with localizing strings according to locale fluidly. – Corbin Miller Mar 29 '17 at 01:23
 - 
                    
 
Here is the updated code for Swift 3
Code :
let calendar = Calendar(identifier: .gregorian)
let weekdayAsInteger = calendar.component(.weekday, from: Date())
To Print the name of the event as String:
 let dateFromat = DateFormatter()
datFormat.dateFormat = "EEEE"
let name = datFormat.string(from: Date())
- 4,149
 - 1
 - 23
 - 43
 
Vladimir's answer worked well for me, but I thought that I would post the Unicode link for the date format strings.
http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns
This link is for iOS 6. The other versions of iOS have different standards which can be found in the X-Code documentation.
- 31
 - 2
 
This way it works in Swift:
    let calendar = NSCalendar.currentCalendar()
    let weekday = calendar.component(.CalendarUnitWeekday, fromDate: NSDate())
Then assign the weekdays to the resulting numbers.
- 12,512
 - 11
 - 67
 - 116
 
- 
                    1NSDate() returns current date for GMT+0 right? You use NSDate here just for example, or calendar component will automatically detect current locale and time shift? – Dima Deplov Jul 08 '15 at 23:33
 
I had quite strange issue with getting a day of week. Only setting firstWeekday wasn't enough. It was also necesarry to set the time zone. My working solution was:
 NSCalendar* cal = [NSCalendar currentCalendar];
 [cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
 [cal setFirstWeekday:1]; //Sunday
 NSDateComponents* comp = [cal components:( NSWeekOfMonthCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSWeekCalendarUnit)  fromDate:date];
 return [comp weekday]  ;
- 5,730
 - 1
 - 39
 - 45
 
Swift 2: Get day of week in one line. (based on neoscribe answer)
let dayOfWeek  = Int((myDate.timeIntervalSinceReferenceDate / (60.0*60.0*24.0)) % 7)
let isMonday   = (dayOfWeek == 0)
let isSunday   = (dayOfWeek == 6)
- 1
 - 1
 
self.dateTimeFormatter = [[NSDateFormatter alloc] init];
self.dateTimeFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; // your timezone
self.dateTimeFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"]; // your locale
self.dateTimeFormatter.dateFormat = @"ccc MM-dd mm:ss";
there are three symbols we can use to format day of week:
- E
 - e
 - c
 
The following two documents may help you.
http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_Patterns
Demo:
you can test your pattern on this website:
- 49
 - 6