Created
May 7, 2009 15:30
-
-
Save anonymous/108162 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
/* This file is part of herzi's playground | |
* | |
* AUTHORS | |
* Sven Herzberg | |
* | |
* Copyright (C) 2009 Sven Herzberg | |
* | |
* This work is provided "as is"; redistribution and modification | |
* in whole or in part, in any medium, physical or electronic is | |
* permitted without restriction. | |
* | |
* This work is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
* | |
* In no event shall the authors or contributors be liable for any | |
* direct, indirect, incidental, special, exemplary, or consequential | |
* damages (including, but not limited to, procurement of substitute | |
* goods or services; loss of use, data, or profits; or business | |
* interruption) however caused and on any theory of liability, whether | |
* in contract, strict liability, or tort (including negligence or | |
* otherwise) arising in any way out of the use of this software, even | |
* if advised of the possibility of such damage. | |
*/ | |
#define _XOPEN_SOURCE // for strptime() - even though strptime(3posix) doesn't mention it | |
#include <time.h> | |
#include <stdio.h> | |
#include <string.h> | |
int | |
main (int argc, | |
char**argv) | |
{ | |
char const* gm_string = "2009-05-07 12:00:00"; | |
char buffer[128]; | |
struct tm time; | |
printf ("%s\n", gm_string); | |
memset (&time, 0, sizeof (time)); | |
strptime (gm_string, "%Y-%m-%d %H:%M:%S", &time); | |
strftime (buffer, sizeof (buffer), "%Y-%m-%d %H:%M:%S %z", &time); | |
printf ("%s\n", buffer); | |
mktime (&time); | |
strftime (buffer, sizeof (buffer), "%Y-%m-%d %H:%M:%S %z", &time); | |
printf ("%s\n", buffer); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment