Created
October 4, 2016 06:45
-
-
Save paulw11/278447c9678428fa584319a4d95c2fac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let date = NSDate() | |
var dateArrayCalendar = [String]() | |
let components = NSCalendar.currentCalendar().components([.Day , .Month , .Year], fromDate: date) | |
let year = components.year | |
let month = components.month | |
let dateFormatatter = NSDateFormatter() | |
let day = 1 // Output is [2,3,4] | |
// let day = 0 than o/p [1,2,3,4,5] | |
dateFormatatter.dateFormat = "MMMM yyyy" | |
let text = dateFormatatter.stringFromDate(date) | |
var startDate = NSDateComponents() | |
let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! | |
startDate.year = year | |
startDate.month = month | |
startDate.day = day | |
let startDateNSDate = calendar.dateFromComponents(startDate)! | |
var dateStart = startDateNSDate // first date | |
let endDate = NSDate() // last date | |
dateFormatatter.dateFormat = "dd" | |
while dateStart.compare(endDate) != .OrderedDescending { | |
// print(fmt.stringFromDate(date)) | |
// Advance by one day: | |
let dateFormat1 = NSDateFormatter() | |
dateFormat1.dateFormat = "dd-MM-yyyy" | |
dateArrayCalendar.append(dateFormatatter.stringFromDate(dateStart)) | |
dateStart = calendar.dateByAddingUnit(.Day, value: 1, toDate: dateStart, options: [])! | |
} | |
print(dateArrayCalendar) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment