/** * @brief convert gmt to unix time * @param [in] year year * @param [in] month month * @param [in] day day * @param [in] hour hour * @param [in] sec second * @return unixtime */ uint64_t convertTokyoTimetoUnixTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) { //static const uint16_t monthday[] = { 0,31,61,92,122,153,184,214,245,275,306,337,365 }; uint16_t onehundredyear; uint64_t result = 0; uint32_t resultDay = 0; static const uint16_t monthday[] = { 0,31,61,92,122,153,184,214,245,275,306,337,365 }; if (month < 3) { month += 12; --year; } month -= 3; // 0:March resultDay = year * 365; onehundredyear = year / 100; resultDay += (year >> 2) - (onehundredyear)+(onehundredyear >> 2); resultDay += monthday[month]; resultDay += day - 1; resultDay -= EPOCH_DAY; result = (uint64_t)resultDay * (24 * 60 * 60); result += hour * (60 * 60); result += min * 60; result += sec; result -= GMT_TOKYO; return result; }