- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Obtaining UNIX current epoch time in milliseconds
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
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
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
тАО04-08-2006 10:30 PM
тАО04-08-2006 10:30 PM
Obtaining UNIX current epoch time in milliseconds
Could anyone show me how I could obtain the current UNIX epoch time in milliseconds?
I've tried using the method below, but this seems to return the current epoch time in seconds
bash-3.00$ perl -e 'print time,"\n";'
1144577446
bash-3.00$
Could anyone kindly help me out by showing me how it's obtained or some scripts to perform this task?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-08-2006 10:57 PM
тАО04-08-2006 10:57 PM
Re: Obtaining UNIX current epoch time in milliseconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2006 01:41 AM
тАО04-09-2006 01:41 AM
Re: Obtaining UNIX current epoch time in milliseconds
You can use Perl's 'Time::HiRes' module.
Calling 'gettimeofday()' in scalar context returns a floating point number of seconds; calling in list context returns time in seconds *and* milliseconds.
cat # ./hitime
#!/usr/bin/perl
use Time::HiRes qw(gettimeofday);
$t = gettimeofday();
print "The time in secs = $t\n";
@t = gettimeofday();
print "The time in secs = $t[0] and msecs = $t[1]\n";
# ./hitime
The time in secs = 1144590040.7041
The time in secs = 1144590040 and msecs = 704642
Regareds!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2006 06:51 AM
тАО04-09-2006 06:51 AM
Re: Obtaining UNIX current epoch time in milliseconds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2006 08:24 PM
тАО04-09-2006 08:24 PM
Re: Obtaining UNIX current epoch time in milliseconds
I'm using a HPUX 11.0 machine with the following spec:
prod-cingtoman :/users/lows >uname -a
HP-UX toman B.11.11 U 9000/800 1854960616 unlimited-user license
Hi James,
The PERL script that you've provided using the Time::HiRes module is great.
However, I was wondering if there is also an equivalent way of performing the same task as the PERL script provided, using Shell scripts?
Thanks
You can use Perl's 'Time::HiRes' module.
Calling 'gettimeofday()' in scalar context returns a floating point number of seconds; calling in list context returns time in seconds *and* milliseconds.
cat # ./hitime
#!/usr/bin/perl
use Time::HiRes qw(gettimeofday);
$t = gettimeofday();
print "The time in secs = $t\n";
@t = gettimeofday();
print "The time in secs = $t[0] and msecs = $t[1]\n";
# ./hitime
The time in secs = 1144590040.7041
The time in secs = 1144590040 and msecs = 704642
Regareds!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2006 02:57 AM
тАО04-11-2006 02:57 AM
Re: Obtaining UNIX current epoch time in milliseconds
You asked if 'gettimeofday()' or an equivalent was available directly in a shell. The answer is "no". Your choice would be the Perl snippet I provided or a C program that calls 'gettimeofday(2)'. Either method can be called from a shell script with the understanding that the will be the overhead of process creation that will perturb the time reported slightly.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2006 10:37 AM
тАО04-11-2006 10:37 AM
Re: Obtaining UNIX current epoch time in milliseconds
Bill Hassell, sysadmin