- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Converting '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
Forums
Discussions
Discussions
Discussions
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
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
02-28-2002 07:19 AM
02-28-2002 07:19 AM
I know I can use time() to get the current Epoch, but I want to compute Epoch for ANY entered date.
Thanks for your assistance,
jls
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 07:31 AM
02-28-2002 07:31 AM
Re: Converting 'date' to Epoch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 07:52 AM
02-28-2002 07:52 AM
Re: Converting 'date' to Epoch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 08:08 AM
02-28-2002 08:08 AM
SolutionThis is one way of doing it, using perl & local timezones:
============================================
#!/opt/perl5/bin/perl
use Time::Local;
my %months=qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11);
my %days=qw(Sun 0 Mon 1 Tue 2 Wed 3 Thu 4 Fri 5 Sat 6);
my ($hour,$min,$sec)=split ':',$ARGV[3];
my $day=$days{$ARGV[0]};
my $month=$months{$ARGV[1]};
my $mday=$ARGV[2];
my $year=$ARGV[4]-1900;
my $time=timelocal($sec,$min,$hour,$mday,$month,$year);
print "$time\n";
===========================================
So, to run it, you'd use:
./date2epoch.pl Thu Feb 28 16:09:55 2002
1014912595
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 08:17 AM
02-28-2002 08:17 AM
Re: Converting 'date' to Epoch
That will work. Do you know how I can do this in C? I'd really like to make this more portable.
jls
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 08:44 AM
02-28-2002 08:44 AM
Re: Converting 'date' to Epoch
Here goes:
====================================
/*
Convert date to epoch time
*/
#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);
}
========================================
Now create a file containing "%c", say, /tmp/datemsk
and then:
export DATEMSK=/tmp/datemsk
Compile your program, then run it:
# ./a.out "`date "+%c"`"
1014914858
the file contains the date format that you wish to use (man getdate).
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2002 09:18 AM
02-28-2002 09:18 AM
Re: Converting 'date' to Epoch
Thank you so much. This is EXACTLY what I was looking for!
jls