Solved

Using Time funcitons

Posted on 2000-04-18
1
221 Views
Last Modified: 2010-04-02
Hi there..

I wanted to use time funcitons in my program to get the date, etc.

I tried doing:

int day;
struct tm current_time;

day = current_time.tm_mday;

printf("%d",day);

This however returns 0, and when I do the same for month and year, I get some huge value..

I tried doing asctime(&current_time);
but this returned a similar answer that was not right..

ps- please only give me c routines... I'm not using c++ for this!
0
Comment
Question by:teatowel
1 Comment
 
LVL 5

Accepted Solution

by:
proskig earned 75 total points
ID: 2725691
You should initialize your structure tm. Example:
 struct tm *pCurrentTime;
 time_t long_time;
 time( &long_time );                /* Get time as long integer. */
 pCurrentTime = localtime( &long_time ); /* Convert to local time. */
 
Now pCurrentTime->tm_mday returns current day of month.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question