Skip to content

Instantly share code, notes, and snippets.

@davidbreyer
Last active October 17, 2022 20:48
Show Gist options
  • Save davidbreyer/ceaa95341a4ded84ca17 to your computer and use it in GitHub Desktop.
Save davidbreyer/ceaa95341a4ded84ca17 to your computer and use it in GitHub Desktop.
Get local date and time in Swift
//
// 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