[問題] 請教傳入日期+ms產生epoch時間
*[36m開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
NA
問題(Question):
如何回傳epoch時間
傳入(YYYMMDD, ms) ms的格式由 0 ~235959999 回傳epoch時間
找到類似的範列如下:
這是抓系統時間:
* timestamp example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, time (for timestamp in second) */
#include <sys/timeb.h> /* ftime, timeb (for timestamp in millisecond) */
#include <sys/time.h> /* gettimeofday, timeval (for timestamp in microsecond) */
int main ()
{
/* Example of timestamp in millisecond. */
struct timeb timer_msec;
long long int timestamp_msec; /* timestamp in millisecond. */
if (!ftime(&timer_msec)) {
timestamp_msec = ((long long int) timer_msec.time) * 1000ll +
(long long int) timer_msec.millitm;
}
else {
timestamp_msec = -1;
}
printf("%lld milliseconds since epoch\n", timestamp_msec);
return 0;
}
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.19.162
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1514435628.A.85F.html
→
12/28 13:10,
8年前
, 1F
12/28 13:10, 1F
→
12/28 13:12,
8年前
, 2F
12/28 13:12, 2F
→
12/28 13:54,
8年前
, 3F
12/28 13:54, 3F
→
12/28 13:55,
8年前
, 4F
12/28 13:55, 4F
→
12/28 14:08,
8年前
, 5F
12/28 14:08, 5F
→
12/28 14:08,
8年前
, 6F
12/28 14:08, 6F
推
12/28 14:17,
8年前
, 7F
12/28 14:17, 7F
→
12/28 17:06,
8年前
, 8F
12/28 17:06, 8F
→
12/28 17:07,
8年前
, 9F
12/28 17:07, 9F
→
12/28 17:08,
8年前
, 10F
12/28 17:08, 10F
→
12/28 17:08,
8年前
, 11F
12/28 17:08, 11F
→
12/28 17:09,
8年前
, 12F
12/28 17:09, 12F
推
12/28 18:26,
8年前
, 13F
12/28 18:26, 13F
→
12/28 18:26,
8年前
, 14F
12/28 18:26, 14F
→
12/28 18:37,
8年前
, 15F
12/28 18:37, 15F
→
12/28 18:37,
8年前
, 16F
12/28 18:37, 16F
→
01/04 12:11,
9年前
, 17F
01/04 12:11, 17F