Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to translate a date

Here you can discuss every aspect of Debian. Note: not for support requests!
Post Reply
Message
Author
xerxesdebian
Posts: 3
Joined: 2006-05-26 16:49

How to translate a date

#1 Post by xerxesdebian »

Is it possible by console command to translate a number given as number (eg:1148581788) human redable format eg: Sat May 27 01:13:23 EEST 2006

Or should I write a program as I did for windows ? (As Im newbie in Linux C will kill me)

Anybody can help me ?

Grifter
Posts: 1554
Joined: 2006-05-04 07:53
Location: Svea Rike

#2 Post by Grifter »

if you run the command uptime, i think it extrapolates it from the output of /proc/uptime (cat /proc/uptime), you could download the source for the procps package and go thru the source of the uptime command for inspiration if you want to make your own (:
Eagles may soar, but weasels don't get sucked into jet engines...

ajdlinux
Posts: 2452
Joined: 2006-04-23 09:37
Location: Port Macquarie, NSW, Australia

#3 Post by ajdlinux »

You can do it in Perl AFAIK, but then again noone wants to program in Perl ;)

lacek
Posts: 764
Joined: 2004-03-11 18:49
Location: Budapest, Hungary
Contact:

#4 Post by lacek »

Of course everyone loves perl... :-D

You can do it like this:

Code: Select all

#!/usr/bin/perl

use POSIX qw(strftime);

$time="";
$format="%Y.%m.%d %H:%M:%S";

if ($ARGV[1]) {
        $format="$ARGV[1]";
}

if ($ARGV[0]) {
        $time=$ARGV[0];
}

print strftime "$format\n", localtime $time;
This code will print the given time in the given format. If you save it as a script, the first argument of it is the time in seconds, and the second is the format.

Post Reply