Coldfusion 计算天、小时、分钟中的秒数
我想将秒转换为天、小时和分钟 目前,它只能工作几小时和几分钟,但不能工作几天。您能否支持我,告诉我我做错了什么:
<cfscript>
seconds = '87400';
midnight = CreateTime(0,0,0);
time = DateAdd("s", seconds, variables.midnight);
date= xxxxxxxxxxxxxxxxxxxxx???
</cfscript>
<cfoutput>
#DateFormat(variables.date, 'd')# not working
#TimeFormat(variables.time, 'HH:mm')#
</cfoutput>
对于值 87400
,预期结果是
- 1 天,0 小时,16 分钟
如果我花费 94152
秒,它将是:
- 1天,3小时,22分钟
我唯一的问题是获得正确的日期...显示了小时和分钟,但不是正确的日期,
谢谢大家的支持
I want to convert seconds to days, hours and minutes
Currently, it works just for hours and minutes but not for days. Can you please support me tell me what I did wrong:
<cfscript>
seconds = '87400';
midnight = CreateTime(0,0,0);
time = DateAdd("s", seconds, variables.midnight);
date= xxxxxxxxxxxxxxxxxxxxx???
</cfscript>
<cfoutput>
#DateFormat(variables.date, 'd')# not working
#TimeFormat(variables.time, 'HH:mm')#
</cfoutput>
For the value 87400
the expected result is
- 1 Days, 0 hours, 16 minutes
If I take 94152
seconds it will be:
- 1 days, 3 hours, 22 minutes
The only issue i have is to get the correct days ... hours and minutes are diplayed but not the correct days
thank you for all the support
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算间隔的一种简单方法是利用 模数运算符:
对于
94152
秒,结果将为:演示 trycf.com
A simple way to calculate the intervals is by taking advantage of the modulus operator:
For
94152
seconds, the results would be:demo trycf.com
我从你的问题中了解到,你不需要沿着时间线获取特定的日期和时间,而是需要将总秒数转换为天、小时和分钟。为此,您不必使用 cfml 时间和日期函数,如 CreateTime() 或 DateAdd()。您可能只需要这些来获取时间轴上的时间或日期参考点,但情况似乎并非如此,否则您会知道起始日期变量的值。因此,你可以用简单的三法则来解决这个问题。可能有更简单的方法,所以我只发布一个替代方法。
我们知道:
因此,您在 cfml 中的计算可能如下所示:
输出:
I understand from your question that you don't need to get a certain date and time along a timeline, but convert a total amount of seconds in days, hours and minutes. To do that you don't necessary need to use cfml time and date functions like CreateTime() or DateAdd(). You just may need these in order to get a reference point of time or date along a timeline, which doesn't seem to be the case, otherwise you would know the value of your starting
date
variable. Thus, you can solve this with plain rule of three. There may be simpler methods, so I'm posting an alternative only.We know that:
Thus, your calcualtion within cfml could be like so:
That outputs: