時間字串的處理

2022-06-08 03:42:09 字數 415 閱讀 4314

let time = '2019-7-24 12:6:23'

//eg:2023年7月24日 12時6分23秒

//方案一:一路replace

time = time.replace('-','年').replace('-','月').replace('-','日').replace(':','時').replace(':','分').replace(':','秒')

//方案二:獲取值的方法,再按需求拼接字串(基於split())

let ary = time.split(/?:|-|:/g);

time = `$年$月$日$時$分$秒`;

//不足十位補零,補零函式,按需使用

let addzero = (val)=>val.length<2?'0'+val:val;

時間字串處理

nsdate轉化為字串 func strtimenow format string yyyy mm dd hh mm data nsdate nsdate string var formatter nsdateformatter formatter.dateformat format return ...

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

題意 小 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...