unixtime to formatted date time

Hi,

I need to take the unix time and format it to a date/time string like this

yyyymmdd,hhmmss

I'm wrting in shell but have tried calling perl, but all the perl options I found on here puts output to Thu Jan 1 00:00:00 1970 format.

Any help?

Cheers
Neil

date '+%Y%m%d,%H%M%S'
# date '+%Y%m%d,%H%M%S'
20101123,175038
# date '+%Y.%m.%d-%H:%M:%S'
2010.11.23-17:50:42
# a=`date '+%Y%m%d,%H%M%S'`                <------ or  a=$(date '+%Y%m%d,%H%M%S')
# echo $a
20101123,175117
#

Sorry,

I think I should have been a little unclear.

I need to take a unixtime and make the conversion output different to standard

example output from perl gives this

perl -le 'print scalar gmtime(1285659552)'
Tue Sep 28 07:39:12 2010

But I need to format the output so its yyyymmdd,hhmmss (20100928,073912).

Cheers,
Neil

If you have gnudate this will work:

$ date --date @1285659552 '+%Y%m%d,%H%M%S'
20100928,173912

In perl:

use POSIX qw(strftime);
print strftime("%Y%m%d,%H%M%S", gmtime(1285659552));
1 Like

That is great...perl option works fine.

The date through an error as it didn't recognise the --date option.

Thanks.
Neil