Get the day of the week from date iOS swift
Problem:
I want to get the day(0,1,2,3...) of the week from the particular date.
Solution:
func getDayOfWeek(_ today:Date) -> Int? {
// let formatter = DateFormatter()
let myCalendar = Calendar(identifier: .gregorian)
let weekDay = myCalendar.component(.weekday, from: today)
return weekDay
}
0 means sunday,1 means monday etc
I want to get the day(0,1,2,3...) of the week from the particular date.
Solution:
func getDayOfWeek(_ today:Date) -> Int? {
// let formatter = DateFormatter()
let myCalendar = Calendar(identifier: .gregorian)
let weekDay = myCalendar.component(.weekday, from: today)
return weekDay
}
0 means sunday,1 means monday etc
Comments
Post a Comment