0

I want to get the monday of this week at the 00:00:00 in base of locale.

This is my code:

func getMonday() -> NSDate {
    var mondaysDate: NSDate {
       let iso8601 =  NSCalendar(calendarIdentifier: NSCalendarIdentifierISO8601)!
       return iso8601.dateFromComponents(iso8601.components([.YearForWeekOfYear, .WeekOfYear ], fromDate: NSDate()))!
    }
    return mondaysDate
}

This function get the last Sunday at 22:00:00 +0000. How can I resolve this issue?

Matteo Serpentoni
  • 553
  • 1
  • 7
  • 19
  • 2
    The result is correct, "Sunday at 22:00:00 +0000" *is* Monday midnight in your time zone. NSDates are always printed in GMT. Use a date formatter to print the date according to your locale. – If you search for "NSDate wrong" you'll find dozens of similar questions with answers. – Martin R Jul 27 '16 at 14:00
  • http://stackoverflow.com/questions/24917483/swift-nsdate-utc-time-and-local-tme. – Martin R Jul 27 '16 at 14:05

0 Answers0