Skip to content

Instantly share code, notes, and snippets.

@GoNinja
Last active September 1, 2016 14:01
Show Gist options
  • Save GoNinja/706a601bf411fd426fb211402f7d978c to your computer and use it in GitHub Desktop.
Save GoNinja/706a601bf411fd426fb211402f7d978c to your computer and use it in GitHub Desktop.
let formatter = NSDateFormatter()
formatter.dateFormat = "y" //A year with at least 1 digit.
formatter.dateFormat = "yy" //A year with 2 digits. If less, it is padded with a zero. It will be truncated to the tens digit if larger.
formatter.dateFormat = "yyyy" //A year with at least 3 digits. If less, it is padded with zeros.
formatter.dateFormat = "yyyy" //A year with at least 3 digits. If less, it is padded with zeros.
formatter.dateFormat = "M" //A year with at least 1 digits.
formatter.dateFormat = "MM" //A month with at least 2 digits. If less, it is padded with zeros.
formatter.dateFormat = "MMM" //Three letter month abbreviation.
formatter.dateFormat = "MMMM" //Full name of month.
formatter.dateFormat = "MMMMM" //One letter month abbreviation. Not unique, January, June, and July are all “J”.
formatter.dateFormat = "d" //A day with at least 1 digit.
formatter.dateFormat = "dd" //A day with at least 2 digits. If less, it is padded with a zero.
formatter.dateFormat = "E" //Or "EE" or "EEE" 3 letter day abbreviation of day name.
formatter.dateFormat = "EEEE" //Full day name.
formatter.dateFormat = "EEEEE" //1 letter day abbreviation of day name. Not unique, Tuesday and Thursday are both “T”.
formatter.dateFormat = "EEEEEE" //2 letter day abbreviation of day name.
formatter.dateFormat = "a" //Period of day (AM/PM).
formatter.dateFormat = "h" //A 1-12 based hour with at least 1 digit.
formatter.dateFormat = "hh" //A 1-12 based hour with at least 2 digits. If less, it is padded with a zero.
formatter.dateFormat = "H" //A 0-23 based hour with at least 1 digit.
formatter.dateFormat = "HH" //A 0-23 based hour with at least 2 digits. If less, it is padded with a zero.
formatter.dateFormat = "m" //A minute with at least 1 digit.
formatter.dateFormat = "mm" //A minute with at least 2 digits. If less, it is padded with a zero.
formatter.dateFormat = "s" //A second with at least 2 digits. If less, it is padded with a zero.
formatter.dateFormat = "S" //Tenths place of fractional second.
formatter.dateFormat = "SS" //Tenths and hundredths place of a fractional second.
formatter.dateFormat = "SSS" //Tenths, hundredths, and thousandths place of a fractional second.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment