Jump to content
  • Advertisement
Sign in to follow this  
Aerts

Getting and writing the date

This topic is 4461 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know some functions that do this but what is the easiest way to get in the end smth. that looks like: Day is Wednesday Month is May Year is 2004

Share this post


Link to post
Share on other sites
Advertisement
Which language? Assuming C or C++, the simplest (but not necessarily shortest) way is to use 'localtime' to get the time, then use a switch/case statement on the values. Probably the shortest (but far from simplest) approach in C++ is to use the Boost Date/Time library.

Share this post


Link to post
Share on other sites
If you're willing to use .NET functions, look into the DateTime class.

Other than that, a search on MSDN should give you some good Win32 options.


EDIT: Wow, no one responds for an hour, then when I want to everyone else jumps on... [smile]

Share this post


Link to post
Share on other sites
If you don't want to use an existing libary, there are lots of date/time classes out there. It is one the the "learning" classes.

theTroll

Share this post


Link to post
Share on other sites
You can get the date and time with two simple ANSI C function calls.


#include <stdio.h> /* Includes printf */
#include <time.h> /* Includes the time functions */

main()
{
time_t current_time; /* Create a time_t variable */
if((time(&current_time)) != -1) /* If time is available */
{
printf("%s",ctime(&current_time)); /* Print time converted to local time */
}
else /* If time is not available */
printf("Error: Time is not available"); /* Print error */
return 0;
}





Hope that helps.

Sifr

[Edited by - Sifr on April 30, 2006 2:06:01 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!