Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to find the day of week?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 389
    Comment on it

    Suppose we want to find the day of the week according to the given date i.e if we want to know the week day of a particular date then the following lines of code will help you to implement this :-

     

    NSDate *date =  [NSDate date];  // get todays date
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;
    
    [dateFormatter setDateFormat:@"EEEE"];   //set the dateFormat
    
    NSLog(@"Week day of selected date -> %@", [dateFormatter stringFromDate:date]);

     

    We can also get the number of day i.e if the day is TUESDAY then the output will be 3. The following code will implement it :-

     

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
     
    NSDateComponents *comps = [gregorian components:NSCalendarUnitWeekday fromDate:[NSDate date]];
    
    NSInteger weekday = [comps weekday];
    
    NSLog(@"Number of day = %ld",(long)weekday);
    

     

    The output for the above lines of code will be :-

     

    Week day of selected date -> Tuesday
    Number of day = 3

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: