zoukankan      html  css  js  c++  java
  • 2-8 R语言基础 日期与时间

    #日期 Date

    > x<-date()
    > class(x)
    [1] "character"


    > x2 <- Sys.Date()
    > class(x2)
    [1] "Date"


    > x3<-as.Date("2018-11-03")
    > class(x3)
    [1] "Date"


    > weekdays(x3) #星期
    [1] "星期六"


    > months(x3) #月份
    [1] "十一月"


    > quarters(x3) #季度
    [1] "Q4"


    > julian(x3) #距离1970-01-01有多少天
    [1] 17838
    attr(,"origin")
    [1] "1970-01-01"


    > x4 <- as.Date("2018-11-01")
    > x4-x3
    Time difference of -2 days


    > as.numeric(x4-x3)
    [1] -2


    > #时间 Time
    > x <- Sys.time()
    > class(x)
    [1] "POSIXct" "POSIXt"


    > y <- as.POSIXct(x)
    > y
    [1] "2018-11-11 15:07:57 CST"


    > z <- as.POSIXlt(x)
    > z

    [1] "2018-11-11 15:07:57 CST"


    > names(unclass(z))
    [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst"
    [10] "zone" "gmtoff"


    > z$sec
    [1] 57.64549


    > as.POSIXct(z)
    [1] "2018-11-11 15:07:57 CST"


    > as.Date("2018-01-01")
    [1] "2018-01-01"
    > x1 <- "Jan 1,2018 01:01"


    > strptime(x1,"%B %d, %Y %H:%M")
    [1] NA

  • 相关阅读:
    设计模式第一次练习
    区间最大数
    魔方数
    螺旋数
    回文串
    最长单词
    指针的应用之学生成绩
    赛马
    突击队任务
    贪婪之骑士
  • 原文地址:https://www.cnblogs.com/hankleo/p/9942177.html
Copyright © 2011-2022 走看看