Epoch in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Epoch in Perl
# 1  
Old 09-18-2012
Epoch in Perl

Hi,
Can anybody tell me how time is calculated in the below or what is actually being done here?
Also can you explain in simple words about epoch time and why it is used?


Quote:
$d = strftime("%m-01-%Y",localtime(time));
@d = split /-/, $d;
$epoch = timelocal(0, 0, 0, $d[1], $d[0]-1, $d[2]);
($sec, $min, $hr, $day, $stmth, $styr, $wday) = localtime($epoch-100);
$styr=$styr+1900;
$stmth=$stmth+1;
$value = timelocal(0, 0, 0, 1, $d[0]-1, $d[2]);
$start = $value-15768000;
$seconds = $value-$start; #mstart
$value=$value-1;
$d="$stmth-$day-$styr";
push(@dates,$d);
$xgrid = 'DAY:2:MONTH:1:MONTH:1:0:%b';

Thanks in advance

Last edited by irudayaraj; 09-18-2012 at 05:59 AM.. Reason: More details needed
# 2  
Old 09-18-2012
1. Read perldoc about localtime and timelocal. If you're still unable to understand, please get back with the specifics and we'll surely help you. If you understand localtime, you'll be able to figure out your code in post #1 by yourself.
2. Epoch is a reference point in time. On most unix systems and programming languages like C, Java, perl, etc, epoch is "01-Jan-1970 00:00:00". Usually current time defined in number of seconds elapsed from epoch is a neater way to handle time related features. There are online tools available for conversion of current time to time in seconds from epoch.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need shell or Perl script to get the epoch time automatically

I need shell or Perl script to get the epoch time automatically Example I need to execute mysql command to delete content less then given epoch time If date is 01-07-2010 (dd-mm-yy) epoch should be lees 7 days mean 23-06-2010 for 23-06-2010 I need epoch time Delete BS_table where... (1 Reply)
Discussion started by: sreedhargouda
1 Replies

2. Shell Programming and Scripting

epoch time

Hi all, I got a file with epoch times like this. 1264010700 1264097400 1263529800 1263762900 1263924300 What I want. I want all epoch times which are > current epoch time written to a file. So everything that is < will be ignored and not written to the file. Thanks (3 Replies)
Discussion started by: stinkefisch
3 Replies

3. Shell Programming and Scripting

epoch conversion

I need to convert an epoch time from a file into a standard UTC time and output it in the same format but I'm not sure what's the best approach here's the input file and the bold part is what I need to convert. 1,1,"sys1",60,300000 2,"E:",286511144960 3,1251194521,"E:",0,0... (2 Replies)
Discussion started by: satchy321
2 Replies

4. News, Links, Events and Announcements

epoch 1234567890

unix epoch time 1234567890 = Fri, 13 Feb 2009 23:31:30 GMT Any geek parties happening in celebration? :D (2 Replies)
Discussion started by: BrewDudeBob
2 Replies

5. Shell Programming and Scripting

Convert date into epoch in Perl on Solaris

Solaris 10 doesn't seem to like me a lot. I am trying to run a simple script to accept date and return epoch of that date: #!/usr/bin/perl -w use strict; use Time::ParseDate; my($date1)="Mon Mar 27 05:54:08 CDT 2009"; chomp $date1; #Convert to seconds since start of epoch my $time1 =... (3 Replies)
Discussion started by: pavanlimo
3 Replies

6. Shell Programming and Scripting

epoch time

Hi, i need to convert below date/time format into epoch time YYYY-m-d H:M below the example: a=`date +"%F %H:%M"` echo $a Convert $a to epoch time ------------------------------------------------------------------------ lets take an example if $a=1.03 here i want the epoch time... (3 Replies)
Discussion started by: ali560045
3 Replies

7. UNIX for Advanced & Expert Users

Epoch time

Guys, i have a question... I have 2 sets of data say "a" and "a+1" which has values in epoch time.. Question is... if i were to get the time difference where diff = "a+1" - "a" can i convert it back to real time duration after the subtraction... OR i need to convert em first before i do the... (2 Replies)
Discussion started by: 12yearold
2 Replies

8. Shell Programming and Scripting

Epoch time

Guys, i have a question... I have 2 sets of data say "a" and "a+1" which has values in epoch time.. Question is... if i were to get the time difference where diff = "a+1" - "a" can i convert it back to real time duration after the subtraction... OR i need to convert em first before i do the... (1 Reply)
Discussion started by: 12yearold
1 Replies

9. UNIX for Dummies Questions & Answers

Epoch

Hi all, i am trying to figure out how i can get a 'Nix box to display epoch time. Is there a command to do this? Do I know what I am talking about or am I an Idiot? Wait dont answer that last question!!!!! Thanx in advance!!!:confused: (2 Replies)
Discussion started by: Bodhi
2 Replies

10. Programming

Epoch problem

I would like to know if the "Epoch" problem (on September 9, 2001) i.e. when the Unix clock counter will hit 100000000 will create a problem for programs that are dependent on system and server times. I am presently part of a team that is working on Oracle database on SUN SOLARIS based servers.... (2 Replies)
Discussion started by: vsomanchi
2 Replies
Login or Register to Ask a Question