string 轉換為 32位時間time t

2021-04-23 02:52:59 字數 590 閱讀 4544

//2008-12-11t13:20:09.74

tm tmtmp;

zeromemory( &tmtmp,sizeof(tm) );

tmtmp.tm_year = _ttoi( lpstr );

tmtmp.tm_year = (tmtmp.tm_year-1970) + 70;

tmtmp.tm_mon  = _ttoi( lpstr + 5 );

tmtmp.tm_mday = _ttoi( lpstr + 8 );

tmtmp.tm_hour = _ttoi( lpstr + 11 );

tmtmp.tm_min = _ttoi( lpstr + 14 );

tmtmp.tm_sec = _ttoi( lpstr + 17 );

time_t

timetmp = mktime( &tmtmp );

如上**:我程式中的時間為32位.所以,對年份有特殊的要求.直接放入2008會導致年份超出範圍而返回-1 (在12行處).

在32位時間中範圍為:1970 - 2038 ,對應的,最小為 70 ,最大為 138.

希望大家能google到此,少些麻煩.

將10位和13位時間戳轉換為時間

請求帶有時間戳請注意,yy mm dd hh mm ss是12小時制格式。yy mm dd hh mm ss是24小時制格式。差別巨大 將10 or 13 位時間戳轉為時間字串 convert the number 1407449951 1407499055617 to date time form...

GNSS時間轉換為UTC 8時間

nmea輸出的gnrmc資料中,時間資訊是格林威治時間,和我們東八區的時間相差八小時,要將其轉換為東八區的時間,可以用以下方法 include math.h include stdbool.h include stdint.h include stdio.h include stdlib.h inc...

SDNU 1462 時間轉換

給定乙個以秒為單位的時間t,要求用 h m s 的格式來表示這個時間。h 表示時間,m 表示分鐘,而 s 表示秒,它們都是整數且沒有前導的 0 例如,若t 0,則應輸出是 0 0 0 若t 3661,則輸出 1 1 1 輸入只有一行,是乙個整數t 0 t 86399 輸出只有一行,是以 h m s ...