Last active
October 17, 2022 20:48
-
-
Save davidbreyer/ceaa95341a4ded84ca17 to your computer and use it in GitHub Desktop.
Get local date and time in Swift
This file contains 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
// | |
// main.swift | |
// ConsoleApp1 | |
// | |
import Foundation | |
let date = NSDate(); | |
let dateFormatter = NSDateFormatter() | |
dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle //Set time style | |
dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle //Set date style | |
dateFormatter.timeZone = NSTimeZone() | |
let localDate = dateFormatter.stringFromDate(date) | |
println("UTC Time") | |
println(date) | |
println("Local Time") | |
println(localDate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment