我想得到午夜以来的秒数.
这是我的第一个猜测:
time_t current;
time(¤t);
struct tm dateDetails;
ACE_OS::localtime_r(¤t, &dateDetails);
// Get the current session start time
const time_t yearToTime = dateDetails.tm_year - 70; // year to 1900 converted into year to 1970
const time_t ydayToTime = dateDetails.tm_yday;
const time_t midnightTime = (yearToTime * 365 * 24 * 60 * 60) + (ydayToTime* 24 * 60 * 60);
StartTime_ = static_cast<long>(current - midnightTime);
Run Code Online (Sandbox Code Playgroud)
Ale*_*x B 12
您可以使用标准C API:
time().struct tm与gmtime_r()或localtime_r().tm_sec,tm_min,tm_hour到零.time_t用mktime().time_t值和新值之间的差异.例:
#include <time.h>
#include <stdio.h>
time_t
day_seconds() {
time_t t1, t2;
struct tm tms;
time(&t1);
localtime_r(&t1, &tms);
tms.tm_hour = 0;
tms.tm_min = 0;
tms.tm_sec = 0;
t2 = mktime(&tms);
return t1 - t2;
}
int
main() {
printf("seconds since the beginning of the day: %lu\n", day_seconds());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9514 次 |
| 最近记录: |