Created
April 14, 2015 16:25
Parses twitter date and outputs a string in new format
This file contains hidden or 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
// 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