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 6157469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:47:29+00:00 2026-05-23T20:47:29+00:00

Here is my program time_play.c : #include <stdlib.h> #include <stdio.h> #include <time.h> int main

  • 0

Here is my program time_play.c :

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

int
main (void)
{
    char *time_str = "2011-07-20 17:30:18";
    time_t time_tm = getdate(time_str);

    printf("str: %s and time: %s \n", time_str, ctime(&time_tm));

    return 0;
} 

And it’s output:

$ gcc -o time_play time_play.c 
$ ./time_play
str: 2011-07-20 17:30:18 and time: Wed Dec 31 16:00:00 1969

It can be seen that time is getting value NULL. Why is it so?

  • 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-05-23T20:47:29+00:00Added an answer on May 23, 2026 at 8:47 pm

    Did you create a template file specifying the date format you are using?

    From the man page:

    User-supplied templates are used to parse and interpret the input string. The templates are text files created by the user and identified via the environment variable DATEMSK.

    Create a file like timetemplate.txt:

    %Y-%m-%d %H:%M:%S
    

    Then set the value of DATEMSK to point to it:

    export DATEMSK=/home/somebody/timetemplate.txt
    

    This code worked for me on OS X, in combination with setting the DATEMSK:

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    
    int main (void)
    {
      char *time_str = "2011-07-20 17:30:18";
      struct tm *time_tm = getdate(time_str);
      time_t t = mktime(time_tm);
    
      printf("str: %s and time: %s", time_str, ctime(&t));
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program here: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include
Okay here's the program I have typed up(stdio.h is included also): /* function main
Here is a quick test program: public static void main( String[] args ) {
Here is a little test program: #include <iostream> class Test { public: static void
Here is the story. I was doing a program, every time the program is
I've got a Schroedinger's Cat type of problem here -- my program (actually the
Here's a short test program: sub foo($;@) { my $sql = shift; my @params
Here's the purpose of my console program: Make a web request > Save results
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
first question here. I'm developing a program in C# (.NET 3.5) that displays files

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.