From: "J." <mailing-lists@xs4all.nl>
To: linux-c-programming@vger.kernel.org
Subject: convert time to UTC, strptime() returns -1 ?
Date: Wed, 1 Oct 2003 21:40:44 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.21.0310012128140.21094-100000@hestia> (raw)
In-Reply-To: <3F69538E00004185@mail-bcm01.alestra.net.mx>
Hello,
I am affraid, I got lost a little in all the time functions that are
arround.
I want to convert a time string to an UTC value. Unfortunatly my program,
and me of course are failing at this. :(
I convert the string with strftime() to a `time struct'.
An then convert that value with strptime(), which returns -1.
The source code.
#include <stdio.h>
#include <time.h>
int main(void) {
struct tm timestruct;
/* the time string to be converted to an UTC value */
char tstr[] = "Sun Sep 28 00:00:04 2003";
char utc[16];
printf("string = %s\n", tstr);
/* Convert / read the time into the time structure */
if(strptime(tstr, "%a %b %d %T %Ey", ×truct) == 0)
return;
else {
printf("strptime() = ");
/* print the time structure, works fine */
printf("%02d %02d %02d:%02d:%02d %2d\n", timestruct.tm_mon,
timestruct.tm_mday, timestruct.tm_hour, timestruct.tm_min,
timestruct.tm_sec, timestruct.tm_year);
/*
* convert the time structure to an UTC time value
* And here the program FAILS. strftime() returns -1
*/
strftime(utc, sizeof(utc), "%s", ×truct);
printf("strftime() = %s\n", utc);
}
return 0;
}
The output is:
string = Sun Sep 28 00:00:04 2003
strptime() = 08 28 00:00:04 2003
strftime() = -1
If the algo or anything else is bad, or if you have tips, hints or
solutions of some kind. I would be very greatfull!
Thnkx, J.
--
LonkyWong
next prev parent reply other threads:[~2003-10-01 19:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-26 15:43 undefined reference to `_fxstat' rgomez
2003-10-01 19:40 ` J. [this message]
2003-10-03 22:28 ` convert time to UTC, strptime() returns -1 ? Luciano Miguel Ferreira Rocha
2003-10-06 21:02 ` convert time to UTC, THNKX ... solved J.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.21.0310012128140.21094-100000@hestia \
--to=mailing-lists@xs4all.nl \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).