The R Project SVN R

Rev

Rev 68948 | Rev 78962 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 73225
Line 1... Line 1...
1
% File src/library/base/man/as.Date.Rd
1
% File src/library/base/man/as.Date.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 1995-2015 R Core Team
3
% Copyright 1995-2017 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{as.Date}
6
\name{as.Date}
7
\alias{format.Date}
7
\alias{format.Date}
8
\alias{as.character.Date}
8
\alias{as.character.Date}
Line 21... Line 21...
21
  Functions to convert between character representations and objects of
21
  Functions to convert between character representations and objects of
22
  class \code{"Date"} representing calendar dates.
22
  class \code{"Date"} representing calendar dates.
23
}
23
}
24
\usage{
24
\usage{
25
as.Date(x, \dots)
25
as.Date(x, \dots)
26
\method{as.Date}{character}(x, format, \dots)
26
\method{as.Date}{character}(x, format, tryFormats = c("\%Y-\%m-\%d", "\%Y/\%m/\%d"),
-
 
27
        optional = FALSE, \dots)
27
\method{as.Date}{numeric}(x, origin, \dots)
28
\method{as.Date}{numeric}(x, origin, \dots)
28
\method{as.Date}{POSIXct}(x, tz = "UTC", \dots)
29
\method{as.Date}{POSIXct}(x, tz = "UTC", \dots)
29
 
30
 
30
\method{format}{Date}(x, \dots)
31
\method{format}{Date}(x, \dots)
31
 
32
 
32
\method{as.character}{Date}(x, \dots)
33
\method{as.character}{Date}(x, \dots)
33
}
34
}
34
\arguments{
35
\arguments{
35
  \item{x}{An object to be converted.}
36
  \item{x}{an object to be converted.}
36
  \item{format}{A character string.  If not specified, it will try
37
  \item{format}{\code{\link{character}} string.  If not specified, it will try
37
    \code{"\%Y-\%m-\%d"} then \code{"\%Y/\%m/\%d"} on the first
38
    \code{tryFormats} one by one on the first non-\code{NA} element, and
-
 
39
    give an error if none works.  Otherwise, the processing is via
-
 
40
    \code{\link{strptime}}.}
38
    non-\code{NA} element, and give an error if neither works.
41
  \item{tryFormats}{\code{\link{character}} vector of \code{format}
39
    Otherwise, the processing is via \code{\link{strptime}}}
42
    strings to try if \code{format} is not specified.}
-
 
43
  \item{optional}{\code{\link{logical}} indicating to return \code{NA}
-
 
44
    (instead of signalling an error) if the format guessing does not succeed.}
40
  \item{origin}{a Date object, or something which can be coerced by
45
  \item{origin}{a \code{Date} object, or something which can be coerced by
41
    \code{as.Date(origin, \dots)} to such an object.}
46
    \code{as.Date(origin, \dots)} to such an object.}
42
  \item{tz}{a time zone name.}
47
  \item{tz}{a time zone name.}
43
  \item{\dots}{Further arguments to be passed from or to other methods,
48
  \item{\dots}{further arguments to be passed from or to other methods,
44
    including \code{format} for \code{as.character} and \code{as.Date}
49
    including \code{format} for \code{as.character} and \code{as.Date}
45
    methods.}
50
    methods.}
46
}
51
}
47
\details{
52
\details{
48
  The usual vector re-cycling rules are applied to \code{x} and
53
  The usual vector re-cycling rules are applied to \code{x} and
Line 158... Line 163...
158
 
163
 
159
## Experiment shows that Matlab's origin is 719529 days before ours,
164
## Experiment shows that Matlab's origin is 719529 days before ours,
160
## (it takes the non-existent 0000-01-01 as day 1)
165
## (it takes the non-existent 0000-01-01 as day 1)
161
## so Matlab day 734373 can be imported as
166
## so Matlab day 734373 can be imported as
162
as.Date(734373, origin = "1970-01-01") - 719529 # 2010-08-23
167
as.Date(734373, origin = "1970-01-01") - 719529 # 2010-08-23
163
## (value from 
168
## (value from
164
## http://www.mathworks.de/de/help/matlab/matlab_prog/represent-date-and-times-in-MATLAB.html)
169
## http://www.mathworks.de/de/help/matlab/matlab_prog/represent-date-and-times-in-MATLAB.html)
165
 
170
 
166
## Time zone effect
171
## Time zone effect
167
z <- ISOdate(2010, 04, 13, c(0,12)) # midnight and midday UTC
172
z <- ISOdate(2010, 04, 13, c(0,12)) # midnight and midday UTC
168
as.Date(z) # in UTC
173
as.Date(z) # in UTC