Skip to content

Instantly share code, notes, and snippets.

@emre-yilmaz
Created May 23, 2017 07:50
Show Gist options
  • Save emre-yilmaz/07bfa901b442a9308317bbdfbad680f9 to your computer and use it in GitHub Desktop.
Save emre-yilmaz/07bfa901b442a9308317bbdfbad680f9 to your computer and use it in GitHub Desktop.

Revisions

  1. emre-yilmaz created this gist May 23, 2017.
    27 changes: 27 additions & 0 deletions SwiftDateSet.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    func addOneDay () -> String {
    //var dateString = "2014-01-12"

    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +zzzz"
    // let s = dateFormatter.date(from: stringDate)
    // print(s)
    let s = Date()
    let calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier(rawValue: NSGregorianCalendar))
    let dateComponent = NSDateComponents()
    dateComponent.day = 1
    //var newDate = calendar?.date(byAdding: dateComponent as DateComponents, to: s!, options: nil)
    let newDate = calendar?.date(byAdding: dateComponent as DateComponents, to: s, options: [])

    let dateString = dateFormatter.string(from: newDate!)

    return dateString
    }

    func nowTime() -> String {
    let nowDate = Date()
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss +zzzz"
    let dateString = dateFormatter.string(from: nowDate)
    return dateString

    }