R语言日期时间函数
Sys.Date( ) returns today's date. 显示当前日期
date() returns the current date and time. 显示当前日期和时间# print today's date
today <-Sys.Date()
format(today, format="%B %d %Y")
"June 20 2007"# convert date info in format 'mm/dd/yyyy'
strDates <- c("01/05/1965", "08/16/1975")
dates <- as.Date(strDates, "%m/%d/%Y")# convert dates to character data
--------------------------------------
strDates <- as.character(dates)
> as.Date('1915-6-16')
[1] "1915-06-16"
> as.Date('1990/02/17')
[1] "1990-02-17"
> as.Date('1/15/2001',format='%m/%d/%Y')
[1] "2001-01-15"
> as.Date('April 26, 2001',format='%B %d, %Y')
[1] "2001-04-26"
> as.Date('22JUN01',format='%d%b%y') # %y is system-specific; use with caution
[1] "2001-06-22"
> bdays = c(tukey=as.Date('1915-06-16'),fisher=as.Date('1890-02-17'),
+ cramer=as.Date('1893-09-25'), kendall=as.Date('1907-09-06'))
> weekdays(bdays)
tukey fisher cramer kendall
"Wednesday" "Monday" "Monday" "Friday"
> dtimes = c("2002-06-09 12:45:40","2003-01-29 09:30:40",
+ "2002-09-04 16:45:40","2002-11-13 20:00:40",
+ "2002-07-07 17:30:40")
> dtparts = t(as.data.frame(strsplit(dtimes,' ')))
> row.names(dtparts) = NULL
> thetimes = chron(dates=dtparts[,1],times=dtparts[,2],
+ format=c('y-m-d','h:m:s'))
> thetimes
[1] (02-06-09 12:45:40) (03-01-29 09:30:40) (02-09-04 16:45:40)
[4] (02-11-13 20:00:40) (02-07-07 17:30:40)
> dts = c("2005-10-21 18:47:22","2005-12-24 16:39:58",
+ "2005-10-28 07:30:05 PDT")
> as.POSIXlt(dts)
[1] "2005-10-21 18:47:22" "2005-12-24 16:39:58"
[3] "2005-10-28 07:30:05"
> dts = c(1127056501,1104295502,1129233601,1113547501,
+ 1119826801,1132519502,1125298801,1113289201)
> mydates = dts
> class(mydates) = c('POSIXt','POSIXct')
> mydates
[1] "2005-09-18 08:15:01 PDT" "2004-12-28 20:45:02 PST"
[3] "2005-10-13 13:00:01 PDT" "2005-04-14 23:45:01 PDT"
[5] "2005-06-26 16:00:01 PDT" "2005-11-20 12:45:02 PST"
[7] "2005-08-29 00:00:01 PDT" "2005-04-12 00:00:01 PDT"
> mydate = strptime('16/Oct/2005:07:51:00',format='%d/%b/%Y:%H:%M:%S')
[1] "2005-10-16 07:51:00"
> ISOdate(2005,10,21,18,47,22,tz="PDT")
[1] "2005-10-21 18:47:22 PDT"
> thedate = ISOdate(2005,10,21,18,47,22,tz="PDT")
> format(thedate,'%A, %B %d, %Y %H:%M:%S')
[1] "Friday, October 21, 2005 18:47:22"
> mydate = as.POSIXlt('2005-4-19 7:01:00')
> names(mydate)
[1] "sec" "min" "hour" "mday" "mon" "year"
[7] "wday" "yday" "isdst"
> mydate$mday
[1] 19 ---------------------
Ref.
http://www.statmethods.net/input/dates.html
http://www.stat.berkeley.edu/classes/s133/dates.html
R语言日期时间函数的更多相关文章
- Oracle日期时间函数大全
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 显示值:07 yyy three digits ...
- MySQL日期时间函数大全(转)
MySQL日期时间函数大全 DAYOFWEEK(date) 返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)mysql> select DAYOFWEEK('1 ...
- PHP函数之日期时间函数date()使用详解
date()函数是我们在php开发中常碰到并且会使用到的一个日期函数,下面我来给大家介绍date()函数的一些基本扮靓和方法,有需要了解的朋友可进入参考 日期时间函数是PHP 的核心组成部分.无需 ...
- 【转】MySQL日期时间函数大全
MySQL日期时间函数大全 1.DAYOFWEEK(date) 返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)mysql> select DAYOFWEEK( ...
- PHP中日期时间函数date()用法总结
date()是我们常用的一个日期时间函数,下面我来总结一下关于date()函数的各种形式的用法,有需要学习的朋友可参考. 格式化日期date() 函数的第一个参数规定了如何格式化日期/时间.它使用字母 ...
- [转]ORACLE日期时间函数大全
本文转自:http://www.cnblogs.com/chuncn/archive/2009/04/29/1381282.html ORACLE日期时间函数大全 TO_DATE格式(以时间: ::2 ...
- JMeter 内置日期(时间)函数总结
JMeter 内置日期(时间)函数总结 by:授客 QQ:1033553122 1. 测试环境 apache-jmeter-3.3 下载地址: http://jmeter.apache.org/c ...
- [转载]ORACLE日期时间函数大全
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 ...
- oracle 日期时间函数
ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 ...
随机推荐
- verilogHDL设计中的同步时序逻辑
引用自夏宇闻教授 1.同步时序逻辑: 是指表示状态的寄存器组的值只能在唯一确定的触发条件发生改变. 只能由时钟的正跳变沿或者负跳变沿触发的状态机就是一例,always@(posedge clk). 1 ...
- xk01创建供应商保存的时候,提示错误“科目800001已经存在”
解决方法:
- Laravel5 路由问题 /home页面无法访问
参考网址:http://stackoverflow.com/questions/11791375/laravel-routes-not-working Laravel5 路由问题 /home页面无法访 ...
- Android应用市场提交入口
应用市场是整个移动生态系统的核心,然而对于中国用户来说,Google Play应用商店却因为种种原因,在中国一直无法长期稳定的运作,又加上Android系统的开源特性,从而在中国造就出大量的第三方应用 ...
- .net 自然排序方式
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- PAT-乙级-1051. 复数乘法 (15)
1051. 复数乘法 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 复数可以写成(A + Bi)的常规 ...
- PHPer 为什么会被 Javaer 鄙视?
最近看了知乎上的一个话题 「在工作中,为什么 Java 程序员常常瞧不起 PHP 程序员?」 个人从业多年,用过的后端语言 ASP.ASP.NET.Java.PHP.Node.js.Python,如果 ...
- 转:[gevent源码分析] 深度分析gevent运行流程
[gevent源码分析] 深度分析gevent运行流程 http://blog.csdn.net/yueguanghaidao/article/details/24281751 一直对gevent运行 ...
- D&F学数据结构系列——插入排序
插入排序(insertion sort) 插入排序由P-1趟(pass)排序组成.对于P=1趟到P=N-1趟,插入排序保证从位置0到位置P-1上的元素为已排序状态.插入排序利用了这样的事实:位置0到位 ...
- hdu 2837 Calculation
公式:a^b%p=a^(b%phi(p)+phi(p))%p b>=phi(p) #include<iostream> #include<stdio.h> #incl ...