如何从给定时间减去分钟数?

时间:2017-06-12 12:41:42

标签: linux date ubuntu

我有一个给定的时间字符串14:00,想要减去5分钟。 怎么能在bash中完成呢?

给我一​​个日期时间对象:date -d "14:00" +'%H:%M' - > 14:00

我尝试减去:date -d "14:00 - 5min" +'%H:%M' - >给出21:01。但是为什么?

当然需要的结果:13:55

2 个答案:

答案 0 :(得分:1)

以下作品:

$ date -d "14:00 5 minutes ago" +'%H:%M'
13:55

我无法解释原因。

答案 1 :(得分:0)

来自gnu日期的信息页面:

     Our units of temporal measurement, from seconds on up to months,
     are so complicated, asymmetrical and disjunctive so as to make
     coherent mental reckoning in time all but impossible.  Indeed, had
     some tyrannical god contrived to enslave our minds to time, to make
     it all but impossible for us to escape subjection to sodden
     routines and unpleasant surprises, he could hardly have done better
     than handing down our present system.  It is like a set of
     trapezoidal building blocks, with no vertical or horizontal
     surfaces, like a language in which the simplest thought demands
     ornate constructions, useless particles and lengthy
     circumlocutions.  Unlike the more successful patterns of language
     and science, which enable us to face experience boldly or at least
     level-headedly, our system of temporal calculation silently and
     persistently encourages our terror of time.

—Robert Grudin, ‘Time and the Art of Living’.

,更相关:

The time may alternatively be followed by a time zone correction,
expressed as ‘SHHMM’, where S is ‘+’ or ‘-’, HH is a number of zone
hours and MM is a number of zone minutes

您尝试执行算术失败,并且日期尝试将表达式“ - 5min”解析为时区校正。