getting the current time in Epoch format

Hi everybody,

I want to get the current time in epoch format (in UNIX or Korn Shell) and store it in a variable called
currentTime. Any response will be highly appreciated:)

Thanks in advance,
omoyne:D

Check this post...

thanks but I was looking for something more straightforward :slight_smile:

I don't get your confusion...you'd asked basically the same question the other day (ie, http://www.unix.com/shell-programming-scripting/136039-filestamps-korn-shell.html#post302420128) and we gave you means to get both current time epoch value, and then the file stats off of a given file/directory...

???

that was timestamp of a FILE!....this question is regard to obtaining the current time in epoch format. There are no files here!!

touch file3
echo `stat -c%Y file3`
1273684993

the echo is above because I often actually use

time_var=$(echo `stat -c%Y file3`)
echo $time_var

There are no date-related commands in ksh.
It would have to be an external utility or a custom program.

What Operating System are you running?

If you have Perl.

currentTime=$(perl -e 'print time;')

Which is also in the link posted in current thread as:

currentTime=$(perl -e "print time();")

to be clear, my own first answer in the other thread was not based on file, but system time as seen by the date utility:

truss date 2>&1 |grep ^time |awk '{print $3;}'

Other responders focused on file stats.

I provided the link to help you do your own research. You really should do some research before asking your questions.

If you had read the post, you would have found:

perl -e "print time();"

It doesn't get any more straight forward than that!