時間字串處理

2021-07-02 12:33:39 字數 1003 閱讀 4884

///nsdate轉化為字串

func strtimenow(format:string = "yyyy-mm-dd hh:mm",data:nsdate = nsdate()) -> string

var formatter = nsdateformatter()

formatter.dateformat = format

return formatter.stringfromdate(mydate)

}///比較兩個間隔一段時間的的時間先後順序。

func comparetime(time1:string,ti: nstimeinterval,time2:string,dateformat:string = "yyyy-mm-dd hh:mm") -> nscomparisonresult

///獲取距離此時一段時間的時間,返回nsdate格式

func getnewtime(time:string,ti: nstimeinterval,dateformat:string = "yyyy-mm-dd hh:mm") -> nsdate

///獲取距離此時一段時間的時間,返回字串格式

func getnewtime(time:string,ti: nstimeinterval,dateformat:string = "yyyy-mm-dd hh:mm") -> string

///將時間字串轉化成指定格式的nsdate時間

func timestringtodate(time:string,dateformat:string = "yyyy-mm-dd hh:mm") -> nsdate?

return mydate

}///將時間字串轉化為特定格式的字串

func timestringtostring(time:string,srcdateformat:string = "yyyy-mm-dd hh:mm",dirdateformat:string = "yyyy年mm

月dd日hh:mm") -> string

時間字串的處理

let time 2019 7 24 12 6 23 eg 2019年7月24日 12時6分23秒 方案一 一路replace time time.replace 年 replace 月 replace 日 replace 時 replace 分 replace 秒 方案二 獲取值的方法,再按需求拼...

航班時間(時間和字串處理)

題意 小 h 的女朋友去中東交換。小 h 並不知道中東與北京的時差。但是小 h 得到了女朋友來回航班的起降時間。小 h 想知道女朋友的航班飛行時間是多少。對於乙個可能跨時區的航班,給定來回程的起降時間。假設飛機來回飛行時間相同,求飛機的飛行時間。起降時間的格式如下 h1 m1 s1 h2 m2 s2...

時間字串

datetime dt datetime.now label1.text dt.tostring 2005 11 5 13 21 25 label2.text dt.tofiletime tostring 127756416859912816 label3.text dt.tofiletimeutc...