Jump to content

Getting time in C in windows

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
sourlemon

sourlemon

    Programmer

  • Members
  • PipPipPip
  • 99 posts
I'm using netbeans to program C in windows. I've programmed it in Linux, and it worked. But I'm having trouble getting the time to work correctly in windows. This is the code.

#include <stdio.h>

#include <time.h>


int main()

{

  time_t now;

  struct tm *d;

  char li[18];


  time(&now);

  d = localtime(&now);


  strftime(li, 18, "%D %T", d);


  printf("%s\n", li);


  return 0;

}



#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Well, based on this reference, your format specifier is invalid. It will be case sensitive, and only uses lower-case d, and doesn't have a T specifier at all.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
sourlemon

sourlemon

    Programmer

  • Members
  • PipPipPip
  • 99 posts
That's interesting. I got the date format from the linux manual. Maybe that's why it only worked on linux. I'll give that a try. Thank you.