time.c 467 B

1234567891011121314151617181920
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <sys/time.h>
  5. int main(int argc, char ** argv)
  6. {
  7. struct timeval time;
  8. int ret = gettimeofday(&time, NULL);
  9. if (ret < 0) {
  10. perror("gettimeofday");
  11. return -1;
  12. }
  13. printf("Current timestamp: %ld\n", time.tv_sec);
  14. return 0;
  15. }