R 时间戳转化
转 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 时间戳转化的更多相关文章
- excel时间戳转化为标准日期(日期转化为日期戳)
最近在学习python将数据导入到excel,发现日期变成数字而不是日期格式的问题. 第一眼看去肯定是excel单元格格式问题,一般excel单元格格式为常规,而常规处理日期时就显示为数字,所以就想到 ...
- js时间戳转化时间格式
// 判断是否前面补0 add0 (m) { return m < 10 ? '0' + m : m }, // 时间转化 timeFormat (timestamp) { // timesta ...
- vue filters 时间戳转化成时间格式
vue filters 时间戳转化成时间格式 filters: { formatDate: function (time) { var re = /-?\d+/ var m = re.exec(tim ...
- JS将时间戳转化为时间
//将时间戳转化为时间 function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1 ...
- jQuery将时间转化为时间戳或将时间戳转化为时间
下面的这段代码,是可以将时间戳转为时间,或者将时间戳转为时间: <script type="text/javascript"> $.extend({ myTime:{ ...
- 囧啊!!时间戳转化为时间出错php
最近写了一个api,测试也没发现啥问题.可是上线之后发现有时api的返回结果不正确.为什么呢? 调我接口的同学给了两个调用示例,理论上两个的结果应该一致,实际结果却不一致. api调用带了一个时间戳参 ...
- 【微信小程序】处理时间格式,时间戳转化展示时间格式问题,调用外部js的默认方法function的问题
默认的 小程序中new Date()显示的时间是这样的: 格式化时间的显示怎么做: 小程序的根目录下util目录下默认有一个util.js文件 其中util.js文件内容是: //数据转化 funct ...
- 时间戳转化为时间&&截取时间的年月日
时间戳转化为正常的时间格式 function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { // 在这里 date.getFullYear() + ' ...
- JavaScript获取时间戳与时间戳转化
第一种方法(精确到秒): var timestamp1 = Date.parse( new Date()); 第二种方法(精确到毫秒): var timestamp2 = ( new Date()). ...
随机推荐
- Docker Compose 部署 Redis 及原理讲解 | 懒人屋
原文:Docker Compose 部署 Redis 及原理讲解 | 懒人屋 Docker Compose 部署 Redis 及原理讲解 4.4k 字 16 分钟 2019-10-1 ...
- 剑指offer 打印从1到最大的n位数
题目描述: 输入数字n,按顺序打印出从1到最大的n位十进制数.比如输入3,则打印出1.2.3一直到最大的3位数999. 分析:注意不能直接输入最大的n位十进制数,因为可能属于大数,这个数无法用int或 ...
- django基础篇06-ModelForm操作及验证
本文内容主要来自银角大王的博客 学习大纲: 一.ModelForm 二.Ajax - 原生(jQuery) - 伪Ajax操作 三.文件上传(预览) - Form提交 - Ajax文件上传 四. 图片 ...
- SPSS 23下载安装和激活
目录 1. 其他版本 2. 安装教程 3. 下载地址 1. 其他版本 参考:https://www.cnblogs.com/coco56/p/11648399.html 2. 安装教程 SPSS 23 ...
- 将Docker主机数据挂在到容器中
dcoker 提供三种不同的方式将数据从宿主机挂载到容器中:volumes,bind mounts, tmpfs.volumes: Docker管理宿主机文件系统的一部分(/var/lib/docke ...
- 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)
链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- error: undefined reference to `cv::imread(std::string const&, int)'
g++ main.cpp -o main `pkg-config --libs --cflags opencv`注意--libs的位置https://stackoverflow.com/questio ...
- LockSupport详解
concurrent包是基于AQS (AbstractQueuedSynchronizer)框架的,AQS框架借助于两个类: Unsafe(提供CAS操作) LockSupport(提供park/un ...
- Ansible笔记(2)--配置清单
一.Ansible Inventory配置及详解 Inventory是ansible管理主机信息的配置文件,默认存放在/etc/ansible/hosts.在使用时通过 -i 或 --inventor ...
- CF1151F Sonya and Informatics (计数dp+矩阵优化)
题目地址 Solution (duyi是我们的红太阳) (这里说一句:这题看上去是一个概率dp,鉴于这题的概率dp写法看上去不好写,我们其实可以写一个计数dp) 首先拿到这个题目我们要能设出一个普通d ...