//
//  DateConversion.swift
//  Zockerhoehle
//
//  Created by Julian-Steffen Müller on 24.09.19.
//  Copyright © 2019 Julian-Steffen Müller. All rights reserved.
//

import Foundation

extension Date {
    func formattedInTimeZone(timezone : TimeZone = .current) -> String {
        // 1) Create a DateFormatter() object.
        let format = DateFormatter()
        
        // 2) Set the current timezone to .current, or America/Chicago.
        format.timeZone = timezone
         
        // 3) Set the format of the altered date.
        format.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
         
        // 4) Set the current date, altered by timezone.
        let dateString = format.string(from: self)
        
        return dateString
    }
}
