我有一個給定的時間字符串14:00
,並且想要減去5分鐘。 這怎麼能在bash中完成?如何從給定時間減去分鐘數?
給了我一個DateTime對象:date -d "14:00" +'%H:%M'
- >14:00
我試過減:date -d "14:00 - 5min" +'%H:%M'
- >給出21:01
。但爲什麼?
當然期望的結果:13:55
。
我有一個給定的時間字符串14:00
,並且想要減去5分鐘。 這怎麼能在bash中完成?如何從給定時間減去分鐘數?
給了我一個DateTime對象:date -d "14:00" +'%H:%M'
- >14:00
我試過減:date -d "14:00 - 5min" +'%H:%M'
- >給出21:01
。但爲什麼?
當然期望的結果:13:55
。
以下工作:
$ date -d "14:00 5 minutes ago" +'%H:%M'
13:55
我無法解釋爲什麼雖然。
從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
您試圖執行算術失敗,並日期試圖解析表達式「 - 5分鐘」的時區修正。
https://stackoverflow.com/questions/3675326/bash-subtracting-10-mins-from-a-given-time – jiveturkey