使用日期类型,我想知道,为什么减法总是返回几天,如何让它返回分钟(或秒等),这可能在第二个例子中
>> 24-dec-2016 - now
== 82
>> 24-dec-2016/0:00 - now
== 82
只是随意的,还是可以影响返回的内容?我尝试了一些改进,但我会欣赏一个方向,反叛/红色方式。
也许在这个问题下面还有一个更重要的事情:"规则"什么是减法,常识,某种讨论和协议,还是只是由谁来实现它? (例如,减去1.1.1.1 - 1
,200x200 - 100
,...)
答案 0 :(得分:3)
您可以使用difference
:
difference 24-dec-2016 now
== 1952:06:01
要获取特定部分,请使用路径语法:
time-diff: difference 24-dec-2016 now
time-diff/2
给出分钟(第二部分)
== 1951:42:11
== 42
答案 1 :(得分:2)
✓查看Francois Vanzeveren's Date-Time Script on REBOL.org
如果你加载它,即
do http://www.rebol.org/download-a-script.r?script-name=date-time.r
然后你可以这样做:
>> ? date-dif
USAGE:
DATE-DIF date1 date2 /y /m /d /ym /md /yd
DESCRIPTION:
Returns the difference between two dates.
DATE-DIF is a function value.
ARGUMENTS:
date1 -- (Type: date)
date2 -- (Type: date)
REFINEMENTS:
/y -- Returns the number of complete years between @date1
and @date2.
/m -- Returns the number of complete months between @date
1 and @date2.
/d -- Returns the number of complete days between @date1
and @date2.
/ym -- Returns the number of full months between @date1 a
nd @date2,
not including the difference in years.
/md -- Returns the number of full days between @date1 and
@date2,
not including the difference in months.
/yd -- Returns the number of full days between @date1 and
@date2,
not including the difference in years.
✓>> ? now
查看/日期的优化
>> ? now
USAGE:
NOW /year /month /day /time /zone /date /weekday /yearday
/precise
DESCRIPTION:
Returns the current local date and time.
NOW is a native value.
REFINEMENTS:
/year -- Returns the year only.
/month -- Returns the month only.
/day -- Returns the day of the month only.
/time -- Returns the time only.
/zone -- Returns the time zone offset from GMT only.
/date -- Returns date only.
/weekday -- Returns day of the week as integer (Monday is
day 1).
/yearday -- Returns day of the year (Julian)
/precise -- Use nanosecond precision
示例:
>> d: 27-7-1973
== 27-Jul-1973
>> d/day
== 27
>> d/month
== 7
>> d/year
== 1973