Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compute date/time string to the corresponding time(2) value in seconds

Status
Not open for further replies.

1yura1

Programmer
Feb 7, 2003
36
0
0
UA
Hi All in forum,

I need to compute/convert date/time string like:
Tue Jul 6 06:24:29 EDT 2004
to the corresponding time(2) value in seconds since the system epoch, using standard Perl functions.

Best Regards,
Yura.
 
The standard Time::Local module should take care of your problem.

You'll need to parse your timestamp for the pertinent info but, otherwise, it should work.

Code:
use Time::Local;
$since_epoch= timelocal($sec, $min, $hour, $mday, $mon, $yr);

Take a look here for time::local documentation.
 
!!!!!!!!!!!!!!Change Epoch time to date!!!!!!!!!!!!!!!!!


#!/usr/bin/perl
use POSIX;

print("\n");
print("\n");
print("Epoch time now : ");
print(time());
print("\n");
print("\n");
print("Enter Epoch time : ");
$wt = <STDIN>;
print("\n");
print("\n");
$timestamp = ctime($wt);
print ($timestamp);
print("\n");
print("\n");
#######


!!!!!!!!!!Change date to Epoch time!!!!!!!!!!!

#!/usr/bin/perl
use POSIX;

print("\n");
print("\n");
print("Epoch time now : ");
print(time());
print("\n");
print("\n");

#
print("\n");
print("Enter second : ");
$sec = <STDIN>;
#
print("\n");
print("Enter minute : ");
$min = <STDIN>;
#
print("\n");
print("Enter hour : ");
$hour = <STDIN>;
#
print("\n");
print("Enter day : ");
$mday = <STDIN>;
#
print("\n");
print("Enter month : ");
$mon1 = <STDIN>;
#
print("\n");
print("Enter year: ");
$year1 = <STDIN>;
#
#
print("\n");
print("Enter day of week \( Sunday -- > 1 \) : ");
$wday = <STDIN>;
#
print("\n");
###
$mon = $mon1 - 1;
$year = $year1 - 1900;
$timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,$wday,0,-1);
print ($timestamp);
print("\n");
print("\n");
##########################

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top