epoch time comparison bsd / MacOSX

北城以北 提交于 2021-01-28 21:43:25

问题


This should be obvious to all but me,

I have a file full of epoch timestamps and I'm trying to get the records from the last 7 days.

So I tried this in my mac:

PAST=$(gdate -d "7 days ago" +%s)
if [ $timeval -gt  $PAST ]; then
  do stuff 
 fi

Example erroneous output:

TS from data, Human fr data, TS from $PAST, Human from $PAST
1419981977690,Tue Jun  9 06 14 50 PST 46967,1421129827,Mon Jan 12 22 17 07 PST 2015
1419400311440,Thu Jan  2 00 17 20 PST 46949,1421129827,Mon Jan 12 22 17 07 PST 2015
1420341489480,Fri Oct 30 06 38 00 PST 46978,1421129827,Mon Jan 12 22 17 07 PST 2015
1421232275040,Thu Jan 22 07 04 00 PST 47007,1421129827,Mon Jan 12 22 17 07 PST 2015

回答1:


The timestamps in your file are in milliseconds, not seconds. Divide them by 1000.



来源:https://stackoverflow.com/questions/28038931/epoch-time-comparison-bsd-macosx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!