//: Playground - noun: a place where people can play

import UIKit

let now = Date()
print(now)  // Ausgabe 2017-02-16 10:50:39 +0000 (GMT-Zeit)

let formatter = DateFormatter()
formatter.dateFormat = "d.M.yyyy H:mm"
let s = formatter.string(from: now)
print(s)    // Ausgabe 16.2.2017 11:52



// Zeit messen; Achtung: Swift läuft im
// Playground sehr langsam
let start = Date()
var sum=0
for _ in 1...10000 {
  sum +=  Int(arc4random_uniform(100))
}

let end = Date()
let seconds = end.timeIntervalSince(start)
print("fertig nach \(seconds) Sekunden")

// rechnen mit Zeiten: in zwei Stunden
let inTwoHours = Date() + 3600 * 2

let cal = Calendar.current
var twoMonths = DateComponents()
twoMonths.month = 2
if let inTwoMonths = cal.date(byAdding: twoMonths, to: Date()) {
  let formatter = DateFormatter()
  formatter.dateFormat = "d.M.yyyy"
  print(formatter.string(from: inTwoMonths))
  
}
