Convert Unix Timestame to real timestamp

Hello,

Did anyone know how to use script (e.g. perl) to conver Unix Timestame to real timestame in GMT+8 ?

1245900787 file:/tmp/a/Test/.txt.swp has created
1245900988 file:/tmp/a/Test/.txt.swp has changed
Thu, 25 Jun 2009 11:33:07 GMT+8 file:/tmp/a/Test/.txt.swp has created
Thu, 25 Jun 2009 03:36:28 GMT+8 file:/tmp/a/Test/.txt.swp has changed

Thank You

HappyDay

---------- Post updated at 03:16 PM ---------- Previous update was at 02:42 PM ----------

#!/usr/bin/perl

$num_args = $#ARGV + 1;
die "Usage: this-program epochtime (something like '1219822177')" if
($num_args != 1);

$epoch_time = $ARGV[0];

($sec,$min,$hour,$day,$month,$year) = localtime($epoch_time);

# correct the date and month for humans
$year = 1900 + $year;
$month++;

printf "%02d/%02d/%02d %02d:%02d:%02d\n", $year, $month, $day, $hour, $min, $sec;

I found the about script, it can help me to convert 1245900789 to 2009/06/25 11:33:09
, but can't help me to covert a file. Did any one know how to change the above perl script to handle the file

Thank You

HappyDay

if shell scripts are an option for you:

>date -u -d @1246018466
Fri Jun 26 12:14:26 UTC 2009

just working with linux date

---------- Post updated at 14:53 ---------- Previous update was at 14:29 ----------

if shell scripts are an option for you:

>date -u -d @1246018466
Fri Jun 26 12:14:26 UTC 2009

just working with linux date

If you have gawk you can do something like:

gawk '{$1=strftime("%c" , $1)}1' file > outfile

Regards

By UNIX timestamp do you mean filetimes - the epoch seconds kept in a the filesystem by the kernel?

perl -e '
  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($ARGV[0]);

$mtime is filetime in epoch seconds

I this what the OP is looking for is a way to print out file timestamps as GMT+8 hrs.

Assuming I am at GMT-4 hrs (East Coast USA), here are two ways which are locale independant.

#!/bin/ksh93

(( $# != 1 )) && {
   echo "usage: $0 epochtime"
   exit 1
}

printf "%(%a, %e %b %Y %T)T GMT+8\n" "#${1} + 12 hours"

exit 0

Example output

$ ./testksh93 1245900787
Thu, 25 Jun 2009 11:33:07 GMT+8

Or if you want to use Perl

#!/bin/perl

use POSIX qw(strftime);

$num_args = $#ARGV + 1;
die "usage: $0 epochtime" if ($num_args != 1);

$offset8 = 8 * 60 * 60;
$epoch_time = $ARGV[0];
$now_string = strftime "%a, %e %b %Y %T GMT+8", gmtime($epoch_time + $offset8);

printf "%s\n", $now_string;

Example output:

$ ./testperl 1245900787
Thu, 25 Jun 2009 11:33:07 GMT+8

~