Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the day of the week with Foundation?

How do I get the day of the week as a string?

like image 666
Moshe Avatar asked Nov 24 '10 16:11

Moshe


People also ask

How to get the day of the week from a date?

weekday () method to get the day of the week as a number, where Monday is 0 and Sunday is 6. isoweekday () method to get the weekday of a given date as an integer, where Monday is 1 and Sunday is 7. strftime () method to get the name of the day from the date. Like Monday, Tuesday.

How do I set the date of the week in Excel?

WeekDay = WEEKDAY ('calendar' [Date]) The default setting is that the weekday starts on Sunday being 1, and then Saturday is 7. You can change it with the 2nd parameter of the Weekday function as below: Return type: 1, week begins on Sunday (1) and ends on Saturday (7). numbered 1 through 7.

How to get the day of the week in JavaScript?

In JavaScript, we can get the day of the week using the getDay() method. This will return a number from 0-6, with 0 being Sunday, and 6 being Saturday. Skip to primary navigation Skip to main content Skip to primary sidebar The Programming Expert Solving All of Your Programming Headaches HTML JavaScript jQuery PHP Python SAS VBA About

How do you find the day of the week from a century-table?

Now add the value for the Century from the Century Table. If the Month is Jan. or Feb. and the Year is a leap year, subtract 1. [1] Add the results from the previous steps. If the resulting number is greater than 6, subtract the highest multiple of 7 in it. Using the resulting number, look up the day of the week in the Weekday-Table.


4 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];
like image 108
Vladimir Avatar answered Oct 12 '22 06:10

Vladimir


Just use these three lines:

CFAbsoluteTime at = CFAbsoluteTimeGetCurrent();
CFTimeZoneRef tz = CFTimeZoneCopySystem();
SInt32 WeekdayNumber = CFAbsoluteTimeGetDayOfWeek(at, tz);
like image 23
John Wilund Avatar answered Oct 12 '22 05:10

John Wilund


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);
like image 15
George Steiner Avatar answered Oct 12 '22 07:10

George Steiner


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]
like image 11
Ashley Mills Avatar answered Oct 12 '22 06:10

Ashley Mills