Xymon Mailing List Archive search

Unix time

5 messages in this thread

list Mario Andre · Tue, 19 Jul 2005 15:01:39 -0300 ·
Hi friends,

Somebody knows how to convert the unix time format to the utc?

Thanks in advance,

Mario.
list Paul van Eldijk · Tue, 19 Jul 2005 20:22:54 +0200 ·
quoted from Mario Andre
On Tuesday 19 July 2005 20:01, mario andre wrote:
Hi friends,

Somebody knows how to convert the unix time format to the utc?
You could use Perl:

    perl -le 'print scalar gmtime($time)'

or, to get local time:

    perl -le 'print scalar localtime($time)'

(fillin the unix timestamp for $time)


HTH
Paul
list Henrik Størner · Tue, 19 Jul 2005 20:25:53 +0200 ·
quoted from Mario Andre
On Tue, Jul 19, 2005 at 03:01:39PM -0300, mario andre wrote:
Somebody knows how to convert the unix time format to the utc?
This little program will do it:

--- showtime.c ---
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    time_t t = atol(argv[1]);

    printf("%s\n", asctime(gmtime(&t)));
    return 0;
}

--- end of file ---

Save this as showtime.c, then "cc -o showtime showtime.c".
Then you can run "showtime 1121797513" and get "Tue Jul 19 18:25:13
2005"


Henrik
list Sue Bauer-Lee · Tue, 19 Jul 2005 14:35:49 -0400 ·
Isn't that this thing provided for by GNU date:

If you're sorting or graphing dated data, your raw date values may
     be represented as seconds since the epoch.  But few people can
     look at the date `946684800' and casually note "Oh, that's the
     first second of the year 2000."

          date --date='2000-01-01 UTC' +%s
          946684800

To convert such an unwieldy number of seconds back to a more
     readable form, use a command like this:
 date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
          2000-01-01 00:00:00 +0000
quoted from Henrik Størner

On Tue, Jul 19, 2005 at 08:25:53PM +0200, Henrik Stoerner wrote:
On Tue, Jul 19, 2005 at 03:01:39PM -0300, mario andre wrote:
Somebody knows how to convert the unix time format to the utc?
This little program will do it:

--- showtime.c ---
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    time_t t = atol(argv[1]);

    printf("%s\n", asctime(gmtime(&t)));
    return 0;
}

--- end of file ---

Save this as showtime.c, then "cc -o showtime showtime.c".
Then you can run "showtime 1121797513" and get "Tue Jul 19 18:25:13
2005"


Henrik

list Mario Andre · Tue, 19 Jul 2005 15:43:54 -0300 ·
Thanks henrik and Paul.
quoted from Sue Bauer-Lee


On 7/19/05, Henrik Stoerner <user-ce4a2c883f75@xymon.invalid> wrote:
On Tue, Jul 19, 2005 at 03:01:39PM -0300, mario andre wrote:
Somebody knows how to convert the unix time format to the utc?
This little program will do it:

--- showtime.c ---
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
   time_t t = atol(argv[1]);

   printf("%s\n", asctime(gmtime(&t)));
   return 0;
}

--- end of file ---

Save this as showtime.c, then "cc -o showtime showtime.c".
Then you can run "showtime 1121797513" and get "Tue Jul 19 18:25:13
2005"


Henrik