Solved

Using Time funcitons

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

706 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

19 Experts available now in Live!

Get 1:1 Help Now