[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Time funcitons

Posted on 2000-04-18
1
Medium Priority
?
234 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 300 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

872 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