Sign in to follow this  
Aerts

Getting and writing the date

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this