Created
February 17, 2017 03:33
-
-
Save StrikeW/a383ba966c73355644d2b10e44eb3222 to your computer and use it in GitHub Desktop.
Linux下获取当前时区的时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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