Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:10:15+00:00 2026-06-14T22:10:15+00:00

I am new to C. When I practicing C to covert time sting to

  • 0

I am new to C. When I practicing C to covert time sting to structure tm back and forth. I noticed some difference. Please advice what I did wrong.

#include <string.h>
#include <stdio.h>
#include <time.h>

/* 
test different format string to strptime
" %A, %b %d, %X %z %Y "
" %A, %b %d, %X %Z %Y "
*/
int main(int argc,char *argv[])
{

   char date[] = "6 Mar 2001 12:33:45";
   char fmt[80];
   struct tm tm;

   if (argc==1) return 0;
   strcpy(fmt,argv[1]);
   memset(&tm, 0, sizeof(struct tm));
   if (strptime(date,"%d %b %Y %H:%M:%S",&tm)==NULL) printf("error\n");
   char buf[128];
   strftime(buf, sizeof(buf), fmt, &tm);
   printf("%s\n", buf);
   printf("%d\n", tm.tm_isdst);
   if (strptime(buf,fmt,&tm)==NULL) printf("error\n");
   else {
   printf("year: %d; month: %d; day: %d;\n",
         tm.tm_year, tm.tm_mon, tm.tm_mday);
   printf("hour: %d; minute: %d; second: %d\n",
         tm.tm_hour, tm.tm_min, tm.tm_sec);
   printf("week day: %d; year day: %d\n", tm.tm_wday, tm.tm_yday);
   }
   return 0;
}

When I use ” %A, %b %d, %X %z %Y ” as conversion format argument, the code provide some result as follow:

 ~/user$ ./test_time " %A, %b %d, %X %z %Y "
 Tuesday, Mar 06, 12:33:45 +0000 2001 
 0
 year: 101; month: 2; day: 6;
 hour: 12; minute: 33; second: 45
 week day: 2; year day: 64

When I change argument to ” %A, %b %d, %X %Z %Y “, the code can not parse the time string which is generated by strftime with exactly the same format.

 ~/user$ ./test_time " %A, %b %d, %X %Z %Y "
  Tuesday, Mar 06, 12:33:45 EET 2001 
 0
 error

Did I miss something to let strptime parse timezone names correctly?

Thanks in advance,

Albert

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:10:16+00:00Added an answer on June 14, 2026 at 10:10 pm

    I’m not sure what you’re doing will work. The glibc source code at github has this to say on the matter:

    case 'Z':
        /* XXX How to handle this? */
        break
    

    followed by some slightly more “meaty” handling of the lowercase 'z' stuff 🙂

    So what’s most likely happening here is that the string pointer isn’t advancing past the EET when the format string is %Z, so that when it tries to process %Y, it complains, rightly so, that EET is not a valid year. This is confirmed by the simple case of "%%" where the code actually does advance the input string pointer rp:

    case '%':
        /* Match the `%' character itself.  */
        match_char ('%', *rp++);
        break;
    

    The Linux man page also states on the extensions (of which 'Z' is one):

    For reasons of symmetry, glibc tries to support for strptime() the same format characters as for strftime(3). (In most cases the corresponding fields are parsed, but no field in tm is changed.)

    In addition the GNU docs state (my italics):

    %Z: The timezone name. Note: Currently, this is not fully implemented. The format is recognized, input is consumed but no field in tm is set.

    So I actually consider this a bug, albeit one that can be easily fixed with a documentation change to stop pretending it can handle Z-type timezones.

    I cannot find any relevant bug in bugzilla so I’ve raised a bug on glibc there. You can track it here.


    Addendum: as per the bug report link in the previous paragraph and the glibc 2.19 release notice, the change I suggested has been made to align the code with the documentation. Hopefully, there’s no bugs in it or I’m going to look pretty silly given it’s only five lines of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just practicing some coding and noticed that I was able to use
I am practicing some examples in Oracle as i am new to it. I
I am very new to Oracle, While i am practicing some examples i encountered
I am new to PHP, and I am practicing with some online tutorials. I
Being new to c++ I've been practicing with questions. One program I wrote includes
I am new at programming and I am practicing my C# programming skills. My
I'm new in using Jasper and I'm practicing of creating programs for accounting. Jasper
I am a new bee to Android App Development . I am practicing the
I am practicing StringToByteArray() on VS2005. But throw exception. Could you please tell me
I am new to Javascript. while practicing i encounter a code regarding event handling.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.