I have the following "C" prorgam where I want to convert GMT into MY
localtime().
#include <stdio.h>
#include <time.h>
main()
{
char *gmt ="20030206102245";
char current_time[50];
time_t secs1;
struct tm tm1;
memset (&tm1, 0, sizeof tm1);
if (csstrptime(gmt, "YYYYMMDDHHMMSS", &tm1) != 0)
{
printf ("Call to csstrptime failed. Date = %s", gmt );
return (1);
}
secs1 = mktime(&tm1);
(void)strftime(current_time, sizeof(current_time),
"%Y %m %d %H %M %S", localtime(&secs1));
printf ("%s\n", current_time);
intQuote:}
csstrptime(char *buf, char *format, struct tm *tm )
{
int year=0, month=0, day=0, hour=0, minute=0, second=0;
tm->tm_isdst = 0;
if (!strcmp(format, "YYYYMMDDHHMMSS") &&
(sscanf(buf, "%4d%2d%2d%2d%2d%2d",
&year, &month, &day, &hour, &minute, &second) == 6))
{
tm->tm_year = year - 1900;
tm->tm_mon = month - 1;
tm->tm_mday = day;
tm->tm_hour = hour;
tm->tm_min = minute;
tm->tm_sec = second;
}
else
return (1);
When I run the program the printf() in the main prints 2003 02 06 10Quote:}
22 45, which is the same as my GMT. The actual result I am looking for
should be 2003 02 06 05 22 45
Can somebody tell me what I need to do make this work. Thanks in
advance for all who answer this post.