Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中打印时间戳毫秒不起作用_R - Fatal编程技术网

在R中打印时间戳毫秒不起作用

在R中打印时间戳毫秒不起作用,r,R,我有一个在R中记录一些信息的应用程序。我正在为此使用日志库。我的问题是,时间戳没有毫秒,而且我并不总是能够获得良好的日志顺序。在日志文件中,R按正确的顺序放置日志,但我使用logstash和es来记录历史和进行监视。因为我得到的时间戳不是正确的日志顺序,所以我想添加毫秒 我尝试使用strtime和%OSn,但似乎不起作用。如果我添加%OS,即使是简单的事情,我也会得到NA: strptime(Sys.time(), "%H:%M:%OS") 我已经看到有更多类似的帖子,但是没有答案,所以我也在

我有一个在R中记录一些信息的应用程序。我正在为此使用日志库。我的问题是,时间戳没有毫秒,而且我并不总是能够获得良好的日志顺序。在日志文件中,R按正确的顺序放置日志,但我使用logstash和es来记录历史和进行监视。因为我得到的时间戳不是正确的日志顺序,所以我想添加毫秒

我尝试使用strtime和%OSn,但似乎不起作用。如果我添加%OS,即使是简单的事情,我也会得到NA:

strptime(Sys.time(), "%H:%M:%OS")
我已经看到有更多类似的帖子,但是没有答案,所以我也在这里发布

我不得不说,我在LinuxUbuntu14.04下使用R3.2.0。如何解决?如何在时间戳中设置毫秒

好的,在使用strftime之后,我得到了毫秒数,但是看起来它们总是0

我有一个日志格式化程序:

logFormatter <- function(record) {
  sprintf('Application(%s) %s [%s] [] %s - %s', format(as.hexmode(Sys.getpid()), width = 8), record$levelname, strftime(record$timestamp, "%Y-%m-%dT%H:%M:%OS3"), record$logger, record$msg)
}
我的日志如下:

loginfo("some info X", logger = MyLogger)
但输出似乎总是在第二个周期的开始:

Application(000018f3) INFO [2015-09-21T11:45:56.000] [] some info 1
Application(000018f3) INFO [2015-09-21T11:45:58.000] [] some info 2
Application(000018f3) INFO [2015-09-21T11:45:58.000] [] some info 3
Application(000018f3) INFO [2015-09-21T11:45:58.000] [] some info 4
Application(000018f3) INFO [2015-09-21T11:45:59.000] [] some info 5
我使用strftime而不是strptime,有一种简单的方法可以显示毫秒,如下所示:

strftime(Sys.time(), format="%Y-%m-%d %H:%M:%OS6")
哪个会输出

[1] "2015-09-21 10:32:58.669559"
这有用吗?

我使用strftime而不是strptime,有一种简单的方法可以显示毫秒,如下所示:

strftime(Sys.time(), format="%Y-%m-%d %H:%M:%OS6")
哪个会输出

[1] "2015-09-21 10:32:58.669559"

这有帮助吗?

要获取毫秒信息,设置

options(digits.secs = 3)
例如,这将给

> strptime(Sys.time(), format =  "%Y-%m-%d %H:%M:%OS")
#[1] "2015-09-21 11:52:09.787 CEST"

这可能对您的情况有所帮助。

要获得毫秒信息,设置

options(digits.secs = 3)
例如,这将给

> strptime(Sys.time(), format =  "%Y-%m-%d %H:%M:%OS")
#[1] "2015-09-21 11:52:09.787 CEST"

也许这对你有帮助。

呃。。。不,我的问题似乎是$timestamp记录,它总是HH:MM:SS.000我如何修复它?你能写一个$timestamp记录的例子吗?呃。。。不,我的问题似乎是记录$timestamp,它总是HH:MM:SS.000我如何修复它?你能写一个记录$timestamp的例子吗?