Real Time Clock. get time-str, set time.
RealTimeClock.cpp
- Committer:
- AkinoriHashimoto
- Date:
- 2015-11-19
- Revision:
- 4:d1c394cd7b63
- Parent:
- 3:3f5628269a53
- Child:
- 5:82e566457502
File content as of revision 4:d1c394cd7b63:
#include "RealTimeClock.h" void RealTimeClock::setSecondsRealTime() { secRT = time(NULL); return; } string RealTimeClock::getHMS8() { setSecondsRealTime(); strftime(buf, 10, "%H:%M:%S", localtime(&secRT)); bufTmp= buf; return bufTmp; } string RealTimeClock::getHMS6() { setSecondsRealTime(); strftime(buf, 8, "%H%M%S", localtime(&secRT)); bufTmp= buf; return bufTmp; } string RealTimeClock::getYMD8() { setSecondsRealTime(); strftime(buf, 10, "%y/%m/%d", localtime(&secRT)); bufTmp= buf; return bufTmp; } string RealTimeClock::getYMD6() { setSecondsRealTime(); strftime(buf, 8, "%y%m%d", localtime(&secRT)); bufTmp= buf; return bufTmp; } bool RealTimeClock::setRealTime(string str, bool JPN) { // now is in range of appropriate time. return setRealTime(A2I(str, 10), JPN); } bool RealTimeClock::setRealTime(long now, bool JPN) { if(JPN) now += 3600* 9; // + JST 9hour. // 1,427,597,183(ISO 8601形式: 2015/03/29 02:46:23Z) // 2,147,483,647秒を経過した (2038/01/19 03:14:07) if(!(1427597183<now && now<2147483600)) return false; if(now == -1) return false; set_time(now); return true; } // End of File