![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
Getting the Date
How can I get the current date with C? Like the year,month,day,hour,minute and second.
|
|
|
|
|
|
#2 | |
|
Hobbyist Programmer
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4
![]() |
Quote:
system("date"); |
|
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Refer to your documentation regarding "time", "asctime", "mktime". You'll encounter additional references along the way. Essentially, you'll start with the number of seconds elapsed since the epoch (January 1, 1970) and feed that to other functions to fill in a structure containing the things you want. The precise functions may turn out to be wrappers for newer functions using 64-bit rather than 32-bit values. Mileage varies, but it's all there for the picking.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
But i need to get those values without prompting, like call a function and return the year value(2005) to a variable.
Like in JavaScript I would write: <script language="javascript"> year = new Date().getFullYear(); </script> |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
hmm...
I'll just request it to be inputed from the user for now. But thanks i didnt know about those dos commands. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4
![]() |
Here's something else I found:
clicky Then scroll down to the time.h and look at the example program, seems like it has what you you are looking for, which is basically same as what DaWei said. Only this is a ready-made code ps: I couldn't read the descriptions of the time functions, Mozilla times me out but example compiled and worked. |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
|
|
|
|
|
|
#8 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Like post #3 said, fill the tmtime structure and get your information from there.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#10 |
|
Programmer
Join Date: May 2005
Location: England
Posts: 61
Rep Power: 4
![]() |
Like posts above, I recommend you use time.h. It's full of functions for getting the time. Here's a reference. Nice and simple.
If you need microseconds, you can use gettimeofday() under *nix. Read the manual pages for how to use it. I can't remember how to get the time in milliseconds under Windows right now. It may come back to me later.
__________________
http://www.nuticulus.net/hackmysig/sig.PNG Give my site a chance, you know you want to ;-) Google will solve 99% of your problems. Including those with your sex life. Caution, may <strike>contain</strike> be nuts. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|