Last active
April 22, 2021 12:46
-
-
Save jedisct1/b7812ae9b4850e0053a21c922ed3e9dc to your computer and use it in GitHub Desktop.
This file contains 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
// CC0 license - No Rights Reserved. | |
#include <time.h> | |
#include <stdio.h> | |
int main(void) | |
{ | |
time_t now = time(NULL); | |
struct tm *tm; | |
int off_sign; | |
int off; | |
if ((tm = localtime(&now)) == NULL) { | |
return -1; | |
} | |
off_sign = '+'; | |
off = (int) tm->tm_gmtoff; | |
if (tm->tm_gmtoff < 0) { | |
off_sign = '-'; | |
off = -off; | |
} | |
printf("%d-%d-%dT%02d:%02d:%02d%c%02d:%02d", | |
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, | |
tm->tm_hour, tm->tm_min, tm->tm_sec, | |
off_sign, off / 3600, off % 3600); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work. Can you add licence (MIT?) please. I want to use it, but i can't.