Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Using Time funcitons

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

790 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