- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem with "time" in C programming
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
тАО05-31-2005 01:41 AM
тАО05-31-2005 01:41 AM
Does this require "time.h"?
"
long now;
struct tm *c_time;
now= time(0);
c_time= localtime(&now); "
and what dictate the value of c_time and now?
Thanks in advance
Solved! Go to Solution.
- Tags:
- localtime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 01:49 AM
тАО05-31-2005 01:49 AM
Solutionc_time is now a pointer to a struct that contains the broken down elements of the local time
The
functions and externals. It also contains the tm structure, which
includes the following members:
int tm_sec; /* seconds after the minute ├в [0,61] */
int tm_min; /* minutes after the hour ├в [0,59] */
int tm_hour; /* hours ├в [0,23] */
int tm_mday; /* day of month ├в [1,31] */
int tm_mon; /* month of year ├в [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday ├в [0,6] */
int tm_yday; /* days since January 1 ├в [0,365] */
int tm_isdst; /* daylight savings time flag */
And strict ANSI wise that code isn't even good:
--8<---
#incluse
#include
:
:
time_t now;
struct tm *c_time;
now = time (0);
c_time= localtime (&now);
(void)printf ("Now: %02d-%02d-%04d %02d:%02d:%02d\n", c_time->tm_mday, c_time->tm_mon + 1, c_time->tm_year + 1900, c_time->tm_hour, c_time->tm_min, c_time->tm_sec);
-->8---
Enjo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 01:54 AM
тАО05-31-2005 01:54 AM
Re: Problem with "time" in C programming
The time() function simply returns the number of seconds since 00:00:00 1-Jan-1970 UTC. If you send a NULL pointer to time the number of seconds is returned; if you send in a non-null pointer to time() the the value is stored in the variable pointed to.
int main()
{
timt_t now = 0;
struct tm *t = NULL;
now = time((time_t *) NULL);
t = localtime(&now);
(void) printf("Year: %d\n",t->tm_year + 1900);
return(0);
} /* main */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 01:29 PM
тАО05-31-2005 01:29 PM
Re: Problem with "time" in C programming
Just another question.. if my time(); = 1117524722, how can i decode them into ,year,month,day,hour,min,sec?
regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 01:48 PM
тАО05-31-2005 01:48 PM
Re: Problem with "time" in C programming
pls refer my program as example
tienna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 05:22 PM
тАО05-31-2005 05:22 PM
Re: Problem with "time" in C programming
- Tags:
- strftime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 05:29 PM
тАО05-31-2005 05:29 PM
Re: Problem with "time" in C programming
Just re-read procura's reply. It's all there.
Now, instead of feeding now with time(), feed it your actual value!? (of course I would no longer call it 'now' but create a new time_t sometime; :-).
In quick perl examples:
# perl -e "print scalar localtime(1117524722)"
Tue May 31 03:32:02 2005
# perl -e "print join (',',localtime(1117524722))"
2,32,3,31,4,105,2,150,1
#
hth,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2005 06:16 AM
тАО06-22-2005 06:16 AM
Re: Problem with "time" in C programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2005 06:19 AM
тАО06-22-2005 06:19 AM
Re: Problem with "time" in C programming
c_time= localtime(&now);
delete c_time; // or use free for C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2005 06:25 AM
тАО06-22-2005 06:25 AM