- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- convert human date to epoch
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
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
тАО06-19-2002 11:52 AM
тАО06-19-2002 11:52 AM
Below is the source for the epoch to human. Could someone elaborate for the reverse ?
#include
int main(argc, argv)
int argc;
char **argv;
{
time_t t=strtoul(argv[1], NULL, 0);
printf("%s", ctime(&t));
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2002 12:17 PM
тАО06-19-2002 12:17 PM
SolutionThe function you are looking for is 'mktime'.
I've attached a small example program that first gets the current time, displays it's epoch seconds and Year,Month,Day,Hr,Min, and Second. It then adds 1 to to day and calls mktime to get a new epoch seconds 1 day (86400 seconds later).
That should be good enough to get you started.
By the way, the stuff is really easy to do in both directions in Perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2002 12:46 PM
тАО06-19-2002 12:46 PM
Re: convert human date to epoch
The GNU date command supports output of epoch, which I find to be rather useful if you need to convert the current time/date stamp to epoch. Of course this only helps if you're trying to convert the current time/date stamp, rather than a supplied human date -> epoch.
You can download a precompiled version of GNU date here:
http://hpux.connect.org.uk/hppd/hpux/Gnu/sh_utils-2.0/
syntax:
date +%s
Hope that helps.
-Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2002 01:02 PM
тАО06-19-2002 01:02 PM
Re: convert human date to epoch
/usr/contrib/bin/perl -e "print time"
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-13-2002 09:07 AM
тАО08-13-2002 09:07 AM
Re: convert human date to epoch
#include
#include
#include
#include
#include
#define FALSE 0
#define TRUE 1
int main(argc,argv)
int argc;
char *argv[];
{
struct tm *dateptr;
time_t date;
int do_exit=FALSE;
if (argc != 2) {
fprintf(stderr, "Usage: %s
exit(1);
}
/* Convert date */
dateptr = getdate(argv[1]);
if (getdate_err != 0) {
fprintf(stderr, "%s: Could not interpret %s. Error = %d\n", argv[0], argv[1], getdate_err);
exit(1);
}
date = mktime(dateptr);
if (date == -1) {
fprintf(stderr, "Could not \"mktime\" for date, errno=%d\n", errno);
exit(1);
}
printf("%d\n", date);
exit(0);
}