Solved

Using Time funcitons

Posted on 2000-04-18
1
220 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now