[ create a new paste ] login | about

Link: http://codepad.org/wJqH2jYZ    [ raw code | output | fork ]

C++, pasted on Feb 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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;
}


Output:
1
2
3
4
local: Tue Feb  8 02:34:36 2011
UTC:   Tue Feb  8 02:34:36 2011

       Tue Feb  8 00:00:00 2011


Create a new paste based on this one


Comments: