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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Epoch time setting

Status
Not open for further replies.

carg1

MIS
Aug 19, 2003
20
0
0
US
If I had a list that had times in it, and I wanted to set the epoch to the first time in that list, how would I pull that off?
 
On Unix, the $^T predefined variable holds the time since the beginning of 1970. This is a number measured in seconds.

print "epoch seconds since 1970: $^T\n";
print " \$localtime: " . localtime ($^T) . "\n";
$newTime = $^T - 3600;
print " take 3,600 seconds away: " . localtime ($newTime) . "\n\n";


The above example print the number of seconds since 1970, then the current date/time and finally 1 hour is taken away from the current time and displayed. You could do it adapting this method.

Regards
Duncan
 
Are you saying you want to set the epoch?
--Paul
 
I'm not sure I understand what you are trying to accomplish.

Epoch is by definition midnight January 1, 1970 UTC. All the time routines are based on 0 = epoch so it cannot be set at an arbitrary point.

If you can try explaining what you want to accomplish we might be able to give you some suggestions.
 
Yes, I want to set the epoch to the first date/time combo in a list, for example:

08/13/03 06:17:29
08/17/03 12:22:04
08/17/03 18:19:20

I would want the epoch to be set as 08/13/03 06:17:29. Unfortunately Duncan, I'm doing it in Windows, I'm sorry I failed to mention that. Is there a predefined variable for windows?
 
Oh, wait, usige you just gave me a thought. If I had it add that date to the epoch and use that as a starting point instead of trying to change the epoch itself, that should work, right?
 
A quick clarification: $^T holds the time the perl interpreter started in unix time (i.e. seconds past start of Epoch). If you need the current time use the time() function.
 
carg,
Have a look at either Dat::Manip, or Date::Calc on search.cpan.org. It'll allow you to get the difference between dates and times using functions like str2time, and time2str

HTH
--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top