計算兩個時間之間的時間差

來源:互聯網
上載者:User

#define TIME_START_YEAR 2000 //起始年份</p><p>typedef struct _TIME<br />{<br /> short year;<br /> short month;<br /> short day;<br /> short hour;<br /> short minute;<br /> short second;<br />}TIME, *LPTIME;</p><p>double Time_to_Second(LPTIME tm) //時間轉換成秒<br />{<br /> int year, month;<br /> unsigned long spanDay =0;<br /> double spandSecond = 0;</p><p> for(year=TIME_START_YEAR; year<tm->year; year++)//隔年<br /> {<br /> if(((year%4 == 0)&&(year%100 != 0)) || (year%400 == 0)) //閏年<br /> spanDay += 366;<br /> else<br /> spanDay += 365;<br /> }<br /> for(month=1; month<tm->month; month++)//隔月<br /> {<br /> if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month== 12) //大月<br /> spanDay += 31;<br /> else if(month==4 || month==6 || month==9 || month== 11) //小月<br /> spanDay += 30;<br /> else //2月<br /> {<br /> if(((year%4 == 0)&&(year%100 != 0)) || (year%400 == 0)) //閏年<br /> spanDay += 29;<br /> else<br /> spanDay += 28;<br /> }<br /> }<br /> spanDay += tm->day - 1; //隔天</p><p> spandSecond = spanDay * 24 * 60 * 60; //天數轉換成秒<br /> spandSecond += tm->hour * 60 * 60; //時轉換成秒<br /> spandSecond += tm->minute * 60; //分轉換成秒<br /> spandSecond += tm->second; //餘秒</p><p> return (spandSecond);<br />}</p><p>double TimeSpan(LPTIME tms, LPTIME tme)<br />{<br /> return Time_to_Second(tme) - Time_to_Second(tms);<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.