I have a following time stamps.
outlist "19980202_0810" "19980202_0815" "19980202_0820"
I want to have "1998-02-02T08:10:00Z" "1998-02-02T08:15:00Z" "1998-02-02T08:20:00Z"
All I can do either "1998-02-02 08:10:00 PST".
time_obj = strptime(outlist, format = "%Y%m%d_%H%M")
strptime
is the import function; strftime
is the format (output) function although I think most people would just use format
:
outlist <- c("19980202_0810", "19980202_0815", "19980202_0820")
time_obj=strptime(outlist, format = "%Y%m%d_%H%M")
format( time_obj , format="%Y-%m-%dT%H:%M:%SZ")
#[1] "1998-02-02T08:10:00Z" "1998-02-02T08:15:00Z" "1998-02-02T08:20:00Z"
At the moment these are POSIXlt items:
> class(time_obj)
[1] "POSIXlt" "POSIXt"
It would be safer to convert to POSIXct:
> time_obj=as.POSIXct(outlist, format = "%Y%m%d_%H%M")
> time_obj
[1] "1998-02-02 08:10:00 PST" "1998-02-02 08:15:00 PST" "1998-02-02 08:20:00 PST"
> class(time_obj)
[1] "POSIXct" "POSIXt"
POSIXlt objects are not handled well in data.frames.
Edit: The print
method for POSIXct objects is documented in ?DateTimeClasses
and the help page for format.POSIXct
is at``srtftime` which I already cited:
strftime(time_obj, tz = "UTC")
[1] "1998-02-02 16:10:00" "1998-02-02 16:15:00" "1998-02-02 16:20:00"
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加