IOS---date Time Format changes

Source: Internet
Author: User
<span id="Label3"></p><span style="color:#FF0000"><span style="color:#FF0000"><strong><span style="font-family:‘Lucida Grande‘,‘Lucida sans Unicode‘,Arial,Verdana,sans-serif; font-size:18px; line-height:2em">1, How to put a string such as "20110826134106" into a random date-time format. Two types are listed Below:</span></strong></span></span><wbr><wbr></wbr><wbr><wbr></wbr>nsstring* string [email protected] "20110826134106";<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsdateformatter*inputformatter = [[[nsdateformatter alloc] init]autorelease];<br><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>[inputformattersetlocale:[[[nslocale alloc] Initwithlocaleidentifier<wbr><wbr></wbr>: @ "en_us"]autorelease]];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>[inputformattersetdateformat:@ "yyyymmddhhmmss"];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsdate*inputdate = [inputformatter datefromstring:string];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>NSLog (@ "date=%@", inputdate);<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr> <wbr><wbr></wbr><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Nsdateformatter*outputformatter = [[[nsdateformatter alloc] init]autorelease];<wbr><wbr></wbr><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>[outputformattersetlocale:[nslocale currentlocale]];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>[outputformattersetdateformat:@ "yyyy mm month dd Day hh" mm min ss seconds "];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr> <wbr><wbr></wbr>Nsstring*str = [outputformatter stringfromdate:inputdate];<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>NSLog (@ "testdate:%@", str);<br style="outline:none"><span style="color:#FF0000"><span style="color:#FF0000">two times the result of this printing is:<br style="outline:none"></span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000">date= 2011-08-26 05:41:06 +0000<br style="outline:none"></span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000"> </span></span><wbr><wbr></wbr><span style="color:#FF0000"><span style="color:#FF0000">testdate:2011 August 26 13:41 06 seconds</span></span><br><br><span style="font-size:18px; color:#FF0000"><span style="font-size:18px; color:#FF0000"><strong>2. ios-nsdateformatter format description:</strong></span></span><br style="outline:none">G: AD era, e.g.<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Yy: the latter 2 digits of the year<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Yyyy: Full year<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>MM: month, Display as 1-12<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>MMM: Month. Shown as abbreviated in English month, such as Jan<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>MMMM: Month. Displays the full name of the month in English. such as Janualy<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><span style="color:#3333FF"><span style="color:#3333FF"> </span></span><wbr><wbr></wbr><span style="color:#3333FF"><span style="color:#3333FF">dd: day, 2 digits, such as</span></span><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>D: day, 1-2-digit display. such as 2<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><span style="color:#3366FF"><span style="color:#3366FF"> </span></span><wbr><wbr></wbr><span style="color:#3366FF"><span style="color:#3366FF">EEE: abbreviated day of the WEEK. such as Sun</span></span><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Eeee: full written day of the week, such as Sunday<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Aa: last Afternoon. am/pm<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><span style="color:#3333FF"><span style="color:#3333FF">H: when, 24-hour system, 0-23</span></span><br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>K: when, 12-hour, 0-11<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>M: minutes, 1-2-bit<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>Mm: min., 2-bit<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>S: seconds, 1-2 Bits<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr> <wbr><wbr></wbr><wbr><wbr></wbr>Ss: seconds, 2 Bits<br style="outline:none"><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr><wbr><wbr></wbr>S: ms<br style="outline:none"><br style="outline:none">Use the date structure frequently:<br style="outline:none">YYYY-MM-DD HH:mm:ss. Sss<br style="outline:none">YYYY-MM-DD HH:mm:ss<br style="outline:none">Yyyy-mm-dd<br style="outline:none">MM DD yyyy<br><span style="color:#FF0000"><span style="color:#FF0000"><br></span></span><span style="font-size:18px; color:#FF0000"><span style="font-size:18px; color:#FF0000"><strong> <span style="font-family:Arial; line-height:26px">3: Sina Weibo interface, get date string</span> conversion</strong></span></span><p style="color:rgb(51,51,51); text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; font-size:14px; line-height:26px; white-space:pre">nsstring*datestr = @ "Wed May 2</span> <span style="font-family:Arial; font-size:14px; white-space:pre; line-height:26px">22:27:08+0800 ";</span></p></p><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-size:14px">nsdateformatter* formater</span> <span style="font-size:14px">=[[nsdateformatter alloc] init];</span> <wbr> <span style="font-size:14px"></span> <wbr></p></p><span style="font-family:Arial; font-size:14px; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; font-size:14px; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">[formater setdateformat:@ "EEE MMM d HH:mm:sszzzz yyyy"]; <wbr> <wbr> </span></span><span style="font-size:14px"><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">nsdate* date = [formaterdatefromstring:datestr]; <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">NSLog (@ "%@", date); <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"> <wbr> <wbr> <wbr></span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">//nsdate* now = [nsdatenow]; <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">double inter = fabs ([datetimeintervalsincenow]); <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">if (inter <60) <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">NSLog ( <span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">@ "1 mins ago!"); <wbr> <wbr> <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">else if (inter< 60*60) <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">NSLog ( <span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">@ "1 hours ago!"); <wbr> <wbr> <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">else if (inter< 60*60*24) <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">NSLog ( <span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)">@ "1 days ago!"); <wbr> <wbr> <wbr> <wbr> </span></span><br style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; color:#333333; line-height:26px; text-align:left; background-color:rgb(255,255,255)"> <wbr>  <wbr> <wbr></span></span><span style="font-family:Arial; color:#333333; background-color:rgb(255,255,255); line-height:26px"><span style="font-family:Arial; color:#333333; background-color:rgb(255,255,255); line-height:26px">NSLog (@ "interval is%f min", inter/60); <wbr> <wbr> </span></span></span><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; font-size:14px; line-height:26px"><wbr> After the above code is executed on the real Machine. found that date is null and the emulator is displayed normally. Internet search found the need to set up local, sure enough, after the real machine normal</span></p></p><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-size:14px">nslocale* local =[[[nslocale alloc]initwithlocaleidentifier</span><wbr><span style="font-size:14px">: @ "en_us"]</span> <wbr> <span style="font-size:14px"> autorelease];</span></p></p><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-size:14px">[formatter setlocale:local];</span></p></p><p style="font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-size:18px; color:#FF0000"><strong>4. Define the format of the week you display</strong></span></p></p><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><span style="font-family:Arial; font-size:14px; color:#000000; line-height:26px"><span style="color:#6600CC">when using the NSDateFormatter conversion date, the day of the week that gets the English alphabet can only be like this, such as sun, Mon, etc.</span></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">Suppose you want the day of the week for capital letters to do This:</span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">Nsarray*weekdayary =</span> [nsarray arraywithobjects:@ "SUN", @ "MON <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> @ "TUE", @ "WED", @ "THU", @ "FRI", @ "SAT", nil];</span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">Dateformatter =</span> <span style="font-size:14px">[[nsdateformatter alloc] init];</span> <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> </span> <wbr> </p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">[dateformatter</span> setdateformat:nslocalizedstring (@ "YYYY. <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> </span> <wbr> <span style="font-size:14px"> MM.dd.eee ", nil)];</span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px; color:#3366FF">//</span> Change the day of the week for the displayed uppercase letters here <wbr> <span style="font-size:14px; color:#3366FF"></span> <wbr> <span style="font-size:14px; color:#3366FF"></span> <wbr> <span style="font-size:14px"> <span style="color:#3366FF"></span><br>[dateformattersetshortweekdaysymbols</span> <wbr>: <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> </span> <wbr> <span style="font-size:14px"> weekdayary];</span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">[dateformatter setlocale:[[nslocale alloc]</span> <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> </span> <wbr> <span style="font-size:14px; color:#3366FF"> Initwithlocaleidentifier</span><wbr><span style="font-size:14px"><span style="color:#3366FF">: @ "en_us"]];</span></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px"><span style="color:#3366FF"></span><br></span></p></p><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><p style="margin:0px; padding:0px; color:rgb(0,0,0)"><span style="font-size:14px">Nstring *str= [dateformatter stringfromdate:[</span> <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"></span> <wbr> <span style="font-size:14px"> NSDate date]];</span></p></p><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><p style="color:rgb(51,51,51); font-family:Arial; line-height:26px; text-align:left; background-color:rgb(255,255,255)"><wbr></p></p><p style="margin:0px; line-height:normal"><p style="margin:0px; line-height:normal"><span style="font-size:18px; color:#FF0000"><strong><span style="font-family:Courier">5<span style="font-family:‘Heiti sC Light‘">.</span> </span> <span style="font-family:‘Heiti sC Light‘">calculate distance How much time is there in a day</span></strong></span></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">nsdate* toDate</span> <wbr> <span style="font-size:14px">= [[nsdate alloc]initwithstring:@ "2012-9-29 0:0:00 +0600"]; </span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">nsdate*</span> <wbr> <span style="font-size:14px"></span> startdate <wbr> <span style="font-size:14px">= [[nsdatealloc] init]; </span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">nscalendar* Chineseclendar = [[nscalendar alloc]initwithcalendaridentifi</span><wbr><span style="font-size:14px">er:nsgregoriancalendar]; </span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><span style="font-size:14px"></span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsuinteger unitflags =</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nshourcalendarunit | Nsminutecalendarunit | Nssecondcalendarunit | Nsdaycalendarunit | Nsmonthcalendarunit | nsyearcalendarunit;</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><span style="font-size:14px"></span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsdatecomponents *cps = [chineseclendar components:unitFlagsfromDate:startDate </span> <wbr> <span style="font-size:14px">todate:todate</span>  <wbr> <span style="font-size:14px">options:0]; </span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><span style="font-size:14px"></span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger Diffhour = [cps hour];</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger</span> <wbr> <span style="font-size:14px"></span> diffmin <wbr> <span style="font-size:14px">= [cpsminute]; </span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger diffsec</span> <wbr> <span style="font-size:14px">= [cps second];</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger diffday</span> <wbr> <span style="font-size:14px">= [cps day];</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger Diffmon</span> <wbr> <span style="font-size:14px">= [cps month];</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">Nsinteger diffyear = [cps year];</span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal; min-height:17px"><span style="font-size:14px"></span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">NSLog (</span> <wbr> <span style="font-size:14px">@ "from-now-%@, diff:years:%d</span> <wbr> <span style="font-size:14px">Months:%d, days;%d, Hours:%d, mins:%d,se c:%d ",</span> <wbr> <span style="font-size:14px"></span><wbr></p></p><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font-family:Courier; line-height:normal"><span style="font-size:14px">[toDate description], diffyear, diffmon, diffday, diffhour,diffmin,diffsec);</span><wbr></p></p><span style="font-size:14px"><span style="font-size:14px">    </span></span><br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article Bo master original articles, blogs, without consent may not be reproduced.</p></p> <p><p>IOS---date Time Format changes</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.