- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- what the diff bet perl timelocal and gnu date
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
тАО10-14-2003 09:13 PM
тАО10-14-2003 09:13 PM
I need to convert a date such as 10/15/2003 to seconds. I tried both timelocal function in perl and also the date command from GNU download from HPUX Porting site in UTAH.
The results is below, but I do not know why the different between the two is 31 days apart. Can someone enlight me on this?
[dev01]/home/perfopr/ict01> cat x
#!/usr/contrib/bin/perl
use Time::Local;
$sec=00;
$min=00;
$hours=00;
$mday=15;
$mon=10;
$year=2003;
$TIME = timelocal($sec, $min, $hours, $mday, $mon, $year);
print "$TIME", "\n";
exit 0
[dev01]/home/perfopr/ict01> perl x
1068825600
[dev01]/home/perfopr/ict01> ./gdate -d "10/15/2003 00:00:00" +%s
1066147200
[dev01]/home/perfopr/ict01> bc
((1068825600 - 1066147200) / 3600 ) / 24
31
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2003 11:30 PM
тАО10-14-2003 11:30 PM
Re: what the diff bet perl timelocal and gnu date
The reason is because the timelocal function in Perl returns the result on mon -1, ie in your case September not October, hence it is 31 days out. To get the correct number of seconds, use $mon=$mon+1;
Cheers
Keely
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2003 11:48 PM
тАО10-14-2003 11:48 PM
Re: what the diff bet perl timelocal and gnu date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2003 02:18 AM
тАО10-15-2003 02:18 AM
Solutionperldoc Time::Local
Therein it is concisely outlined how Perl is treating Dates, and what the functions from the module expect as arguments, and what they return.
Remember in Perl context matters (viz. scalar vs. list) when you assign the functions' return values.
Please also have a look at
perldoc -f localtime
perldoc POSIX
Of the last you may find the strftime() function of interest, which lets you format date strings as used to from Unix date commands.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2003 04:05 AM
тАО10-15-2003 04:05 AM
Re: what the diff bet perl timelocal and gnu date
for checking purposes, it can be helpful to convert the seconds into something human friendly, e.g.:
# SECS=1068825600
# echo 0d${SECS}=Y|adb
but be aware that your TZ setting influences the result
regards,
John K.