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()). ...
随机推荐
- EL&JSTL笔记
# 今日内容 1. JSP: 1. 指令 2. 注释 3. 内置对象 2. MVC开发模式 3. EL表达式 4. JSTL标签 ...
- 设计模式开闭原则--java
静态工厂模式 + 反射控制入参范围 public interface IPrinter { void print(); } public class CanonPrinter implements I ...
- SPSS Statistics 多个版本的下载安装激活步骤
SPSS 23:https://www.cnblogs.com/coco56/p/11648386.html SPSS25:https://www.cnblogs.com/coco56/p/11648 ...
- nroff - 用 groff 模拟 nroff 命令
总览 (SYNOPSIS) nroff [ -h ] [ -i ] [ -mname ] [ -nnum ] [ -olist ] [ -rcn ] [ -Tname ] [ file... ] 描述 ...
- windows使用cmd命令输出文件清单和文件树
输出目录树:tree /f > d:\filetree.txt 输出目录清单:dir /s /b > d:\filelist.txt
- 关于jsp 获得当前绝对路径的方法
方法1) request.getRequestURL(); 方法2) request.getScheme()+"://"+request.getServerName()+&quo ...
- 【学习】016 MySQL数据库优化
MySQL如何优化 表的设计合理化(符合3NF) 添加适当索引(index) [四种: 普通索引.主键索引.唯一索引unique.全文索引] SQL语句优化 分表技术(水平分割.垂直分割) 读写[写: ...
- php内置函数分析之array_diff_assoc()
static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */ { uint ...
- Redis 启动警告解决
Redis 启动警告解决[转] [root@centos224]# service redisd start 21985:M 24 Nov 04:07:20.376 * Increased maxim ...
- CSS3边框 阴影 box-shadow
box-shadow是向盒子添加阴影.支持添加一个或者多个. box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式]; 参数介绍: box-sh ...