乙個好用的日期時間類 c

2021-04-27 08:43:22 字數 2761 閱讀 9881

class cdatetime

;#endif

#include

#include "datetime.h"

using namespace std;

cdatetime::cdatetime():m_millisecondflag(true)

#else

localtime_r(&m_ttime,&m_sttime);

#endif

} cdatetime::cdatetime(time_t ttime):m_millisecondflag(false)

#else

localtime_r(&m_ttime,&m_sttime);

#endif

} cdatetime::cdatetime(const struct tm& sttime):m_millisecondflag(false)

cdatetime::cdatetime(int iyear,int imonth, int iday,

int ihour,int iminute,int isecond)

:m_millisecondflag(false)

const std::string cdatetime::shortdatetime()

;sprintf(sdatetime,"%04d%02d%02d%02d%02d%02d",

year(),month(),day(),hour(),minute(),second());

return string(sdatetime);

} const std::string cdatetime::longdatetime(char chsep1,char chsep2)

;sprintf(sdatetime,"%04d%c%02d%c%02d %02d%c%02d%c%02d",

year(),chsep1,month(),chsep1,day(),

hour(),chsep2,minute(),chsep2,second());

return string(sdatetime);

}const std::string cdatetime::longdatetimewithmillisec(char chsep1,char chsep2)

;sprintf(sdatetime,"%04d%c%02d%c%02d %02d%c%02d%c%02d%c%03d",

year(),chsep1,month(),chsep1,day(),

hour(),chsep2,minute(),chsep2,second(),chsep2,millisecond());

return string(sdatetime);

} const std::string cdatetime::shortdate()

;sprintf(sdate,"%04d%02d%02d",year(),month(),day());

return string(sdate);

} const std::string cdatetime::longdate(char chsep)

;sprintf(sdate,"%04d%c%02d%c%02d",year(),chsep,month(),chsep,day());

return string(sdate);

} time_t cdatetime::getvalue()

inline const struct tm& cdatetime::getstruct()

inline int cdatetime::year()

inline int cdatetime::month()

inline int cdatetime::day()

inline int cdatetime::hour()

inline int cdatetime::minute()

inline int cdatetime::second()

inline int cdatetime::dayofweek()

inline int cdatetime::dayofyear()

inline int cdatetime::millisecond()

int cdatetime::submillisecond(cdatetime &dt)

int millise***s = 0;

if(this->getvalue() >= dt.getvalue())

if(millise***s > 1000 * 61 * 60)

millise***s += millisecond() - dt.millisecond();

return m_millisecondflag?millise***s:0;

}//增加或者減少幾個自然月

const std::string cdatetime::getnewdatebymonth(int newmonth)

else

int day = this->day();

//校驗本月是否有該天

while(day > 0)

day--;

}return this->longdate();

}//增加或者減少幾天

const std::string cdatetime::getnewdatebyday(int newday)

#else

localtime_r(&m_ttime,&m_sttime);

#endif

return this->longdate();

}

Arrow 乙個好用的日期時間Python處理庫

使用arrow處理時間格式資料 安裝pip install arrow使用 獲取當前時間import arrow 獲取當前utc時間 t arrow.utcnow print t 獲取local時間 n arrow.now print n 通過utcnow 和now 分別獲取了utc時間和local...

設計乙個日期類和時間類

define cry secure no warings 問題描述 設計乙個日期類和時間類,編寫display函式用於顯示日期和時間。要求 display函式作為類外的普通函式,分別在time和date類中將display宣告為友元函式。在主函式中呼叫display函式,display函式分別引用t...

C 實現乙個日期類

include using namespace std class date public bool is invalid date 判斷日期是否無效 return false public int day in month if is leap year return days month pub...