Skip to content

Instantly share code, notes, and snippets.

@StrikeW
Created February 17, 2017 03:33
Show Gist options
  • Save StrikeW/a383ba966c73355644d2b10e44eb3222 to your computer and use it in GitHub Desktop.
Save StrikeW/a383ba966c73355644d2b10e44eb3222 to your computer and use it in GitHub Desktop.
Linux下获取当前时区的时间
// Linux获取当前时区的时间
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
char buf[80];
time_t now = time(0);
struct tm *tm;
tm = localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d %X", tm);
printf("Current datetime:%s, in seconds:%ld\n", buf, mktime(tm));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment