// Since codepad.org is set for UTC, this doesn't show as much as it will on a system
// not set for UTC.
time_t local_midnight(time_t x) {
struct tm t;
localtime_r(&x, &t);
t.tm_sec = t.tm_min = t.tm_hour = 0;
return mktime(&t);
}
int main() {
time_t now = time(0);
cout << "local: " << asctime(localtime(&now));
cout << "UTC: " << asctime(gmtime(&now));
time_t midnight = local_midnight(now);
cout << "\n " << asctime(localtime(&midnight));
return 0;
}