- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Getting date and time from from time.h
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2007 10:50 PM
тАО12-11-2007 10:50 PM
I want to get the system date and time i am tryong man pages of local time
Here is my code
#include
int main()
{
tm TimeNow;
char *pTime = localtime(&TimeNow);
printf("%s",*pTime);
return 0;;
}
It says " tm undefined "
Can anyone help me in getting through this problem.
thanks and regards
Vikram
Solved! Go to Solution.
- Tags:
- time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2007 11:20 PM
тАО12-11-2007 11:20 PM
Solutionstruct tm *TimeNow;
time_t Now;
...
Now = time ( NULL );
TimeNow = localtime ( &Now );
printf ( "%s", ctime ( &Now ) );
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2007 11:42 PM
тАО12-11-2007 11:42 PM
Re: Getting date and time from from time.h
You have to define TimeNow as smthing.
There is nothin like tm.
BR,
KApil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2007 12:22 AM
тАО12-12-2007 12:22 AM
Re: Getting date and time from from time.h
#include
#include
int main() {
struct tm *TimeNow;
time_t now = time(NULL);
TimeNow = localtime(&now);
printf("%s", asctime(TimeNow));
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2007 02:04 AM
тАО12-12-2007 02:04 AM
Re: Getting date and time from from time.h
In a real language like C++ there is. :-)
struct tm == tm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2007 02:12 AM
тАО12-12-2007 02:12 AM
Re: Getting date and time from from time.h
;-)
Anyway, looks like "pure" C.
Here is the struct
struct tm {
int tm_sec; /* second (0-61, allows for leap seconds) */
int tm_min; /* minute (0-59) */
int tm_hour; /* hour (0-23) */
int tm_mday; /* day of the month (1-31) */
int tm_mon; /* month (0-11) */
int tm_year; /* years since 1900 */
int tm_wday; /* day of the week (0-6) */
int tm_yday; /* day of the year (0-365) */
int tm_isdst;/* non-0 if daylight savings time is in effect */
};
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2007 12:57 AM
тАО12-13-2007 12:57 AM
Re: Getting date and time from from time.h
Yes, i missed struct there.
I am also able to achieve this by following 2 lines of code
#include
long t = time(0);
cout << asctime(localtime(&t))<
thanks and regards
Vikram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2007 02:01 AM
тАО12-13-2007 02:01 AM
Re: Getting date and time from from time.h
If you are going to use iostream, you should go whole hog: :-)
#include
#include
#include
struct my_pt : public std::time_put
struct my_ibase : public std::ios_base {};
int main() {
std::tm *TimeNow;
std::time_t now = std::time(NULL);
TimeNow = std::localtime(&now);
// printf("%s", asctime(TimeNow));
const char format[] = "%a %b %d %H:%M:%S %Y\n";
my_pt::iter_type o_itr(std::cout);
my_ibase ibase;
tp.put(o_itr, ibase, ' ', TimeNow, format, format + (sizeof(format)-1));
}
- Tags:
- time_put
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-13-2007 05:02 AM
тАО12-13-2007 05:02 AM
Re: Getting date and time from from time.h
In my previous reply there is 1 wrong sorry for that
it should be as below
#include
time_t t = time(0);
cout << asctime(localtime(&t))<
thanks and regards
Vikram