Skip to content

Instantly share code, notes, and snippets.

@jchudzynski
Created April 14, 2015 16:25
Show Gist options
  • Save jchudzynski/62339fcd10bbe8fce256 to your computer and use it in GitHub Desktop.
Save jchudzynski/62339fcd10bbe8fce256 to your computer and use it in GitHub Desktop.
Parses twitter date and outputs a string in new format
// Playground - noun: a place where people can play
import UIKit
func parseTwitterDate(twitterDate:String, outputDateFormat:String)->String?{
let formatter = NSDateFormatter()
formatter.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
var indate = formatter.dateFromString(twitterDate)
var outputFormatter = NSDateFormatter()
outputFormatter.dateFormat = "hh:mm a dd:MM:yy"
var outputDate:String?
if let d = indate {
outputDate = outputFormatter.stringFromDate(d)
}
return outputDate;
}
var str = "Wed Sep 02 19:38:03 +0000 2009"
var outputDateFormat = "hh:mm a dd:MM:yy"
parseTwitterDate(str, outputDateFormat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment