今天犯了了個很低階的錯誤,想把uidatepickview的預設選中時間設定為當前時間的下一天的11:30,我的思路:首先獲取當前時間---將當前時間字串化-----擷取次字串,分理處當前的年月日中得日----將日+1----然後字串拼接成自己想要的日期格式-------將拼接成的日期轉化成nsdate-------然後設定預設時間
我犯的錯誤,將字串轉化為時間的時候,一直想象nsdate的會有這樣的方法,結果檢視nsdate的api沒有查到。犯錯就是沒有第一時間想到:nsdateformatter.
下面看看我設定的**:
uidatepicker * pick = [[uidatepicker alloc] initwithframe:cgrectmake(0, self.view.frame.size.height-215, 320, 215)];
pick.minimumdate = [nsdate date];
nsdate * tempdate = [nsdate datewithtimeintervalsincenow:24*60*60];
nsstring * str = [nsstring stringwithformat:@"%@",tempdate];
nsstring * result = [[str substringwithrange:nsmakerange(0, 10)] stringbyappendingformat:@" 11:30"];
nsdateformatter * formatter = [[nsdateformatter alloc] init];
[formatter setdateformat:@"yyyy-mm-dd hh:mm"];
nsdate * resultdate = [formatter datefromstring:result];
[pick setdate:resultdate];
[pick addtarget:self action:@selector(pickvaluechanged:) forcontrolevents:uicontroleventvaluechanged];
self.datepicker = pick;
nslocale *locale = [[nslocale alloc] initwithlocaleidentifier:@"zh_cn"];//設定為中文顯示
pick.locale = locale;
[self.view addsubview:pick];
if (iphone5)
else
#pragma mark - pick事件
-(void)pickvaluechanged:(uidatepicker *)apick
else
} uidatepicker * pick = [[uidatepicker alloc] initwithframe:cgrectmake(0, self.view.frame.size.height-215, 320, 215)];
pick.minimumdate = [nsdate date];
nsdate * tempdate = [nsdate datewithtimeintervalsincenow:24*60*60];
nsstring * str = [nsstring stringwithformat:@"%@",tempdate];
nsstring * result = [[str substringwithrange:nsmakerange(0, 10)] stringbyappendingformat:@" 11:30"];
nsdateformatter * formatter = [[nsdateformatter alloc] init];
[formatter setdateformat:@"yyyy-mm-dd hh:mm"];
nsdate * resultdate = [formatter datefromstring:result];
[pick setdate:resultdate];
[pick addtarget:self action:@selector(pickvaluechanged:) forcontrolevents:uicontroleventvaluechanged];
self.datepicker = pick;
nslocale *locale = [[nslocale alloc] initwithlocaleidentifier:@"zh_cn"];//設定為中文顯示
pick.locale = locale;
[self.view addsubview:pick];
if (iphone5)
else
#pragma mark - pick事件
-(void)pickvaluechanged:(uidatepicker *)apick
else
} 以此總結,告誡自己,不要犯這些蛋疼的問題!
boost ptime轉化為時間字串
物件的定義 boost posix time ptime p boost gregorian date 2010,3,5 2010年3月5號0點 boost posix time ptime p1 boost gregorian date 2010,3,5 boost posix time hour...
linux shell中,字串時間轉化為時間戳
bin bash 獲取2小時前的時間 log date date d 2 hours ago f t echo log date 獲取2小時前的整點時間 start date date d 2 hours ago f h 00 00 echo start date 將start date字串時間轉化...
將字串轉化為整型
函式名稱 atol 函式原型 long atol cha r str 函式功能 將字串轉換成乙個長整數 函式返回 轉換後的數值 引數說明 str 待轉換為長整型的字串 所屬檔案 include include int ma in 把字串轉換成整數 收藏 題目 輸入乙個表示整數的字串 把該字串轉換成整...