转 http://stackoverflow.com/questions/1962278/dealing-with-timestamps-in-r

You want the (standard) POSIXt type from base R that can be had in 'compact form' as a POSIXct (which is essentially a double representing fractional seconds since the epoch) or as long form in POSIXlt (which contains sub-elements). The cool thing is that arithmetic etc are defined on this -- see help(DateTimeClasses)

Quick example:

R> now <- Sys.time()
R> now
[] "2009-12-25 18:39:11 CST"
R> as.numeric(now)
[] 1.262e+09
R> now + # adds seconds
[] "2009-12-25 18:39:21 CST"
R> as.POSIXlt(now)
[] "2009-12-25 18:39:11 CST"
R> str(as.POSIXlt(now))
POSIXlt[:], format: "2009-12-25 18:39:11"
R> unclass(as.POSIXlt(now))
$sec
[] 11.79 $min
[] $hour
[] $mday
[] $mon
[] $year
[] $wday
[] $yday
[] $isdst
[] attr(,"tzone")
[] "America/Chicago" "CST" "CDT"

As for reading them in, see help(strptime)

As for difference, easy too:

R> Jan1 <- strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
R> difftime(now, Jan1, unit="week")
Time difference of 51.25 weeks

Lastly, the zoo package is an extremely versatile and well-documented container for matrix with associated date/time indices.

timestamp to datestr:

datestr = as.character(as.POSIXlt(timestamp, origin="1970-01-01"))

R 时间戳转化的更多相关文章

  1. excel时间戳转化为标准日期(日期转化为日期戳)

    最近在学习python将数据导入到excel,发现日期变成数字而不是日期格式的问题. 第一眼看去肯定是excel单元格格式问题,一般excel单元格格式为常规,而常规处理日期时就显示为数字,所以就想到 ...

  2. js时间戳转化时间格式

    // 判断是否前面补0 add0 (m) { return m < 10 ? '0' + m : m }, // 时间转化 timeFormat (timestamp) { // timesta ...

  3. vue filters 时间戳转化成时间格式

    vue filters 时间戳转化成时间格式 filters: { formatDate: function (time) { var re = /-?\d+/ var m = re.exec(tim ...

  4. JS将时间戳转化为时间

    //将时间戳转化为时间 function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1 ...

  5. jQuery将时间转化为时间戳或将时间戳转化为时间

    下面的这段代码,是可以将时间戳转为时间,或者将时间戳转为时间: <script type="text/javascript"> $.extend({ myTime:{ ...

  6. 囧啊!!时间戳转化为时间出错php

    最近写了一个api,测试也没发现啥问题.可是上线之后发现有时api的返回结果不正确.为什么呢? 调我接口的同学给了两个调用示例,理论上两个的结果应该一致,实际结果却不一致. api调用带了一个时间戳参 ...

  7. 【微信小程序】处理时间格式,时间戳转化展示时间格式问题,调用外部js的默认方法function的问题

    默认的 小程序中new Date()显示的时间是这样的: 格式化时间的显示怎么做: 小程序的根目录下util目录下默认有一个util.js文件 其中util.js文件内容是: //数据转化 funct ...

  8. 时间戳转化为时间&&截取时间的年月日

    时间戳转化为正常的时间格式 function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { // 在这里 date.getFullYear() + ' ...

  9. JavaScript获取时间戳与时间戳转化

    第一种方法(精确到秒): var timestamp1 = Date.parse( new Date()); 第二种方法(精确到毫秒): var timestamp2 = ( new Date()). ...

随机推荐

  1. Find The Multiple (水题)

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repr ...

  2. JUNIT4 GroboUtils多线程测试

    阅读更多 利用JUNIT4,GroboUtils进行多线程测试 多线程编程和测试一直是比较难搞的事情,特别是多线程测试.只用充分的测试,才可以发现多线程编码的潜在BUG.下面就介绍一下我自己在测试多线 ...

  3. Chrome开发者工具详解(四)之Elements、Console、Sources面板

    Elements面板 实时编辑DOM节点和CSS样式 双击DOM树视图里面的节点,可以实时编辑标签属性,修改的效果会立刻反应在浏览器里 点击右侧Style面板,可以实时修改CSS的属性值,这里面的所有 ...

  4. Windows 环境下安装redis 及其PHP Redis扩展

    1.安装Redis (1)这里选择在github官网上下载Redis,地址:Redis下载地址 下载压缩包(如下图),并解压到本地目录,我放在D:\redis (2)验证Redis安装是否成功打开命令 ...

  5. verilog中的timescale

    `timescale是Verilog HDL 中的一种时间尺度预编译指令,它用来定义模块的仿真 时的时间单位和时间精度.格式如下: `timescale  仿真时间单位/时间精度 注意:,不能为其它的 ...

  6. 2019 计蒜之道 初赛 第二场 A 百度AI小课堂-矩阵问题 ( 等差数列求和公式)

    题目背景 ​91029102 年 99 月 11 日,百度在 X 市 XX 中学举办了一场 AI 知识小课堂,本场 AI 知识小课堂老师教授了一些矩阵的相关知识,因为矩阵在 AI 人工智能中也有相当的 ...

  7. 【学习】020 Redis

    Java缓存机制 Java中要用到缓存的地方很多,首当其冲的就是持久层缓存,针对持久层谈一下:  要实现java缓存有很多种方式,最简单的无非就是static HashMap,这个显然是基于内存缓存, ...

  8. java 类记载器

    转载:  https://blog.csdn.net/javazejian/article/details/73413292

  9. python 小游戏,和电脑玩剪刀石头布

    # -*- coding: utf-8 -*- """ Created on Fri Oct 25 16:28:12 2019 if判断综合演练,剪刀石头布 @autho ...

  10. C++ GUI Qt4学习笔记05

    C++ GUI Qt4学习笔记05   qtc++正则表达式 QIntValidator           --  只让用户输入整数 QDoubleValidator     --  只让用户输入浮 ...