开发者

Creating time from a string

I want to subtract time as to get a result of hour and minutes (not a date), for instance

02/26/2006 06:25 PM

minus

02/26/2006 06:23 PM

开发者_开发百科

Into

2 Minutes

Also, the times I want to subtract from are strings, not datetime objects.


Convert the strings to date/time objects. Then you will be able to take advantage of date functions. Get the total difference in minutes and simple division / mod will give you the total hours and minutes.

<cfset time1   = parseDateTime("02/26/2006 06:25 PM")>
<cfset time2   = parseDateTime("02/26/2006 06:23 PM")>
<cfset diff    = dateDiff("n", time2, time1)>
<cfset hours   = int(diff / 60)>
<cfset minutes = diff mod 60>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜