关于linux中date +%s获取绝对秒数异常的问题

lwjpker 2013-11-13 09:51:54
我在一个做统计的shell脚本里用date +%s获取当前的绝对秒数,但是运行了一个月左右,这条命令获得的值就变为了空值,第一次出现时以为是个意外,就没在意,重启脚本后就没管了。但是这次是第二次出现这个问题了,实在不清楚是什么原因,请问是否有人遇到过这样的问题,如果知道还希望不吝赐教,谢谢啦~~
...全文
684 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwjpker 2013-11-14
  • 打赏
  • 举报
回复
引用 8 楼 ys1109 的回复:
接上,date +%S(大写的S),可以满足lz要求,date --help 查看(%S Second(00..60))
你搞错了吧,命令那样写是可以获得绝对秒数的,只是脚本在运行了一个多月之后,那句突然获得的值就变成空值了,之前的一个多月是什么问题的没有的。
ys1109 2013-11-14
  • 打赏
  • 举报
回复
接上,date +%S(大写的S),可以满足lz要求,date --help 查看(%S Second(00..60))
ys1109 2013-11-14
  • 打赏
  • 举报
回复
从lz描述"统计的shell脚本里用date +%s获取当前的绝对秒数"这里的%s(是大写字母);
ljc007 2013-11-14
  • 打赏
  • 举报
回复
引用 4 楼 lwjpker 的回复:
为什么啊?我上边那样用也好好的跑了一个多月啊,只是突然出现获得空值的情况,不是一直这样的。
先别管为什么,加上双引号试试到底是否有用。
mymtom 2013-11-13
  • 打赏
  • 举报
回复
建议试试,% 有可能有特殊含义 Quoting Quoting is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to preserve the literal meaning of the special characters in the next paragraph, prevent reserved words from being recognized as such, and prevent parameter expansion and command substitution within here-document processing (see Here-Document ). The application shall quote the following characters if they are to represent themselves: | & ; < > ( ) $ ` \ " ' <space> <tab> <newline> and the following may need to be quoted under certain circumstances. That is, these characters may be special depending on conditions described elsewhere in this volume of POSIX.1-2008: * ? [ # ˜ = % The various quoting mechanisms are the escape character, single-quotes, and double-quotes. The here-document represents another form of quoting; see Here-Document .
lwjpker 2013-11-13
  • 打赏
  • 举报
回复
为什么啊?我上边那样用也好好的跑了一个多月啊,只是突然出现获得空值的情况,不是一直这样的。
mymtom 2013-11-13
  • 打赏
  • 举报
回复
建议用 date "+%s"
lwjpker 2013-11-13
  • 打赏
  • 举报
回复
嗯,想到要判断返回值了,但是还是想知道这个到底是什么原因。
iasky 2013-11-13
  • 打赏
  • 举报
回复
这种情况没有看到过啊。 建议在脚本中判断下返回值 $? 是否为0
Date 对象属性constructor 返回对创建此对象的 Date 函数的引用。prototype 使您有能力向对象添加属性和方法。Date 对象方法getDate() 从 Date 对象返回一个月的某一天 (1 ~ 31)。getDay() 从 Date 对象返回一周的某一天 (0 ~ 6)。getFullYear() 从 Date 对象以四位数字返回年份。getHours() 返回 Date 对象的小时 (0 ~ 23)。getMilliseconds() 返回 Date 对象的毫秒(0 ~ 999)。getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。getMonth() 从 Date 对象返回月份 (0 ~ 11)。getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。getTime() 返回 1970 年 1 月 1 日至今的毫秒数。getTimezoneOffset() 返回本地时间与格林威治标准时间 (GMT) 的分钟差。getUTCDate() 根据世界时从 Date 对象返回月的一天 (1 ~ 31)。getUTCDay() 根据世界时从 Date 对象返回周的一天 (0 ~ 6)。getUTCFullYear() 根据世界时从 Date 对象返回四位数的年份。getUTCHours() 根据世界时返回 Date 对象的小时 (0 ~ 23)。getUTCMilliseconds() 根据世界时返回 Date 对象的毫秒(0 ~ 999)。getUTCMinutes() 根据世界时返回 Date 对象的分钟 (0 ~ 59)。getUTCMonth() 根据世界时从 Date 对象返回月份 (0 ~ 11)。getUTCSeconds() 根据世界时返回 Date 对象的秒钟 (0 ~ 59)。getYear() 已废弃。 请使用 getFullYear() 方法代替。parse() 返回1970年1月1日午夜到指定日期(字符串)的毫秒数。setDate() 设置 Date 对象月的某一天 (1 ~ 31)。setFullYear() 设置 Date 对象的年份(四位数字)。setHours() 设置 Date 对象的小时 (0 ~ 23)。setMilliseconds() 设置 Date 对象的毫秒 (0 ~ 999)。setMinutes() 设置 Date 对象的分钟 (0 ~ 59)。setMonth() 设置 Date 对象月份 (0 ~ 11)。setSeconds() 设置 Date 对象的秒钟 (0 ~ 59)。setTime() setTime() 方法以毫秒设置 Date 对象。setUTCDate() 根据世界时设置 Date 对象月份的一天 (1 ~ 31)。setUTCFullYear() 根据世界时设置 Date 对象的年份(四位数字)。setUTCHours() 根据世界时设置 Date 对象的小时 (0 ~ 23)。setUTCMilliseconds() 根据世界时设置 Date 对象的毫秒 (0 ~ 999)。setUTCMinutes() 根据世界时设置 Date 对象的分钟 (0 ~ 59)。setUTCMonth() 根据世界时设置 Date 对象的月份 (0 ~ 11)。setUTCSeconds() setUTCSeconds() 方法用于根据世界时 (UTC) 设置指定时间的秒字段。setYear() 已废弃。请使用 setFullYear() 方法代替。toDateString() 把 Date 对象的日期部分转换为字符串。toGMTString() 已废弃。请使用 toUTCString() 方法代替。toISOString() 使用 ISO 标准返回字符串的日期格式。toJSON() 以 JSON 数据格式返回日期字符串。toLocaleDateString() 根据本地时间格式,把 Date 对象的日期部分转换为字符串。toLocaleTimeString() 根据本地时间格式,把 Date 对象的时间部分转换为字符串。toLocaleString() 据本地时间格式,把 Date 对象转换为字符串。toString() 把 Date 对象转换为字符串。toTimeString() 把 Date 对象的时间部分转换为字符串。toUTCString() 根据世界时,把 Date 对象转换为字符串。UTC() 根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。valueOf() 返回 Date 对象的原始值。

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧