Monday, February 13, 2017

//get current time and date
let currentTime = NSDate()
let dateFormat = NSDateFormatter()
dateFormat.dateFormat = "yyyy/MM/dd HH:mm:ss"
print(dateFormat.stringFromDate(currentTime))

here is the chart which will be the most useful date field symbols

Format Description Example
"y" A year with 1 digit. 1 AD -> "1"
42 AD -> "42"
2014 AD -> "2014"
"yy" A year with exactly 2 digits.
If less then it will padded with 0.
It will be truncated to the tens digit if larger
1 AD -> "01"
42 AD -> "42"
2014 AD -> "14"
"yyy" A year with at least 3 digits.
If less then it will padded with 0.
1 AD -> "001"
42 AD -> "042"
2014 AD -> "2014"
"yyyy" A year with at least 3 digits.
If less then it will padded with 0.
1 AD -> "0001"
42 AD -> "0042"
2014 AD -> "2014"
"M" A month with at least 1 digits. June -> "6"
December -> "12"
"MM" A month with at least 2 digits.
If less then it will padded with 0.
June -> "06"
December -> "12"
"MMM" Three letter month abbreviation June -> "Jun"
December -> "Dec"
"MMMM" Full name of month June -> "June"
December -> "December"
"MMMMM" One letter month abbreviation
January, June and July are "J"
June -> "J"
December -> "D"
"d" A day with at least 1 digit 4 -> "4"
24 -> "24"
"dd" A day with at least 2 digit.
If less then it will padded with 0.
4 -> "04"
24 -> "24"
"E","EE" or "EEE" 3 letter day abbreviation of day name Wednesday -> "Wed"
Thursday -> "Thu"
"EEEE" Full day name Wednesday -> "Wednesday"
Thursday -> "Thursday"
"EEEEE" 1 letter day abbreviation of day name.
Teusday and Thursday are "T"
Wednesday -> "W"
Thursday -> "T"
"EEEEEE" 2 letter day abbreviation of day name Wednesday -> "We"
Thursday -> "Th"
"a" period of day (AM/PM) 7 PM -> "PM"
10 AM -> "AM"
"h" 12 hour based with at least 1 digit 7 PM -> "7"
10 AM -> "10"
"hh" 12 hour based with at least 2 digit.
If less then it will padded with 0.
7 PM -> "07"
10 AM -> "10"
"H" 24 hour based with at least 1 digit 7 PM -> "19"
10 AM -> "10"
"HH" 24 hour based with at least 2 digit.
If less then it will padded with 0.
7 PM -> "19"
9 AM -> "09"
"m" A minute with at least 1 digit 40 -> "40"
1 -> "1"
"mm" A minute with at least 2 digit.
If less then it will padded with 0.
40 -> "40"
1 -> "01"
"s" A second with at least 1 digit 40 -> "40"
1 -> "1"
"ss" A second with at least 2 digit.
If less then it will padded with 0.
40 -> "40"
1 -> "01"
"S" A tenth place of fraction second 123 ms -> "1"
7 ms -> "0"
"SS" A tenth and hundredths place of fractions second 123 ms -> "12"
7 ms -> "00"
"SSS" A tenth, hundredths and thousandths place of fractions second 123 ms -> "123"
7 ms -> "007"

No comments:

Post a Comment