//當前日前日期
nsdate *today = [nsdate
date];
//時區
nstimezone*zone = [nstimezone
systemtimezone];
//設定間隔
_interval = [zone secondsfromgmtfordate: today];
//今天+8小時(中國上海時區)
today = [today datebyaddingtimeinterval: _interval];
//獲取
明天日期
nsdate *tomorrowdate = [[nsdate
alloc]initwithtimeinterval:24 * 60 * 60
sincedate:[nsdate
date]];
//日曆
nscalendar *
calendar
= [nscalendar
currentcalendar];
//comps裡能夠分離出時間年月日等資訊
nsdatecomponents *comps
= [calendar
components
:(nsyearcalendarunit
| nsmonthcalendarunit
| nsdaycalendarunit
| nsweekcalendarunit
| nsweekdaycalendarunit
|nsweekdayordinalcalendarunit
| nshourcalendarunit
)fromdate:tomorrowdate];
//獲取當前星期幾
nsinteger weekday= [comps
weekday];
//將nsstring型別轉換成nsdate
nsdate *serverdate = [datefomatter datefromstring:servertimestr];
nsdate *createdate = [datefomatter datefromstring:createtimestr];
//算出兩個date的間隔
nstimeintervalbetweentime = [serverdate timeintervalsincedate:createdate];
//分離出標準格式裡的年月日時分秒
nsdateformatter*datefomatter = [[nsdateformatter
alloc
]init];
[datefomatter
setdateformat
:@"yyyy-mm-dd hh:mm:ss"];
//將string換成formatter形式
nsdate *stringdate = [datefomatter datefromstring:string];
//formatter為月和日
[datefomatter setdateformat:@"mm-dd"];
//提取字串中月和日
nsstring *str1 = [datefomatter stringfromdate:stringdate];
Swift String 一些經常用法
直接上 字串 1 推斷字串是否為空 var test1str var test1str2 string string println test1str test1str.isempty 沒有值 有值 println test1str2 test1str2.isempty 沒有值 有值 2 計算字串的...
oracle死鎖解決經常用法(屢試不爽)
1.查詢被鎖的情況 select object name,machine,s.sid,s.serial from v locked object l,dba objects o v session s where l.object id o.object id and l.session id s....
ios常用技術 獲取系統時間
使用該方法獲取的系統時間格式為 yyyy mm dd hh mm ss 獲取當前系統時間 nsdate currentdate nsdate date 獲取當前時間,日期 nsdateformatter dateformatter nsdateformatter alloc init datefor...