swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dates


From: Marcus G. Daniels
Subject: Re: dates
Date: 30 Mar 2000 11:18:46 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "LRA" == M Lang & S Railsback <address@hidden> writes:

LRA> It would be really cool if R uses the same Unix (Posix?) time_t
LRA> format that we're already using in our models.

Suppose you have encoded a time (2/10/00) like so:

#include <time.h>
#include <stdio.h>

int
main ()
{
  struct tm time;

  time.tm_year = 2000 - 1900;
  time.tm_mon = 2 - 1;
  time.tm_mday = 10;
  time.tm_hour = 0;
  time.tm_min = 0;
  time.tm_sec = 0;

  printf ("%ld\n", mktime (&time));
}

$ TZ=GMT ./a.out 
950140800

In R, you can do a similar coding like so:

With the `date' package (which uses 1/1/1960 as the origin):

> library(date)
> as.numeric(as.date("2/10/2000")-(as.date("1/1/1970")-as.date("1/1/1960"))) * 
> 3600 * 24
[1] 950140800

With the `chron' package (which, like Posix, uses 1/1/1970 as the origin)

> library(chron)
> as.numeric(dates(c("2/10/00"))) * 3600 * 24


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]