添加毫秒时间戳(bash中,UNIX) [英] Add milliseconds to timestamp (bash, unix)

查看:258
本文介绍了添加毫秒时间戳(bash中,UNIX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:这显然是不可能的,看下面的Barmars回答

我使用下面很多命令来创建归档目的的时间戳。我想毫秒添加到字符串。那可能吗?我使用这个脚本在两个OSX和Linux,这样在两个工作将是很好的解决方案。是有史以来秒或四舍五入带或不带毫秒? (在几分钟或四舍五入?)

 日期-n +%Y%m%d日%H%M%S


解决方案

我不认为有一种方法可移植做到这一点。请参阅 POSIX的strftime规范,它没有提及毫秒或任何纳秒。

此外,输入到的strftime 结构TM 。这种结构的规范此处是,它不包括再说了precise比秒。纳秒都在的timespec 结构,但这主要用于时间段,而不是时钟时间,而且也为系统维护时钟时间比第二分辨率更没有要求

EDIT: This is apparently not possible, see Barmars answer below.

I use the command below a lot to create a timestamp for archiving purposes. I'd like to add milliseconds to the string. Is that possible? I use this script on both osx and linux, so a solution that works on both would be nice. Are seconds ever rounded up or down with or without milliseconds? (Are minutes rounded up or down?)

date -n +%Y%m%d%H%M%S

解决方案

I don't think there's a way to do this portably. See the POSIX strftime specification, it doesn't mention anything about milliseconds or nanoseconds.

Furthermore, the input to strftime is a struct tm. The specification of this structure is here and it doesn't include anything more precise than seconds. Nanoseconds are in the timespec structure, but this is mostly used for time periods, not clock time, and there's no requirement for the system to maintain the clock time to more than second resolution.

这篇关于添加毫秒时间戳(bash中,UNIX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆