Crystal报表将秒转换为Timespan格式的函数 [英] Crystal Report Function for converting Seconds to Timespan format
问题描述
我有一个水晶报告,其中通过饼图显示代理的全天活动。在详细信息部分中显示:
- 活动[string]
- StartedAt [DateTime] / li>
- EndedAt [DateTime]
- Duration [EndedAt和StartedAt之间的差异(以秒为单位 - 整数)
报告数据是GroupedBy活动,并按持续时间汇总。
目前持续时间以秒为单位,但我需要格式化02h: 30m:22s:15ms。为此,我在公式工作室编辑器中的Crystal Reports中编写了一个自定义函数,如下所示,但它看起来语法不正确(关键字Long上的错误消息:缺少一个变量类型(例如'String')。 )。
函数GetTimeSpanString(秒为长)
Dim ts As TimeSpan = TimeSpan.FromSeconds(seconds) ;
GetTimeSpan = string.Format({0:D2} h:{1:D2} m:{2:D2} s:{3:D3} ms,
ts.Hours,
ts.Minutes,
ts.Seconds,
ts.Milliseconds)
结束函数
解决方案您可以轻松更改我的 ElapsedTime()函数来满足您的需求。
I have a crystal report where it shows the Agent's activities throughout the day with a pie chart. In the details section it is displaying:
- Activity [string]
- StartedAt [DateTime]
- EndedAt [DateTime]
- Duration [The difference between EndedAt and StartedAt in seconds - Integer]
Report data is GroupedBy Activity and summarized by Duration.
Currently Duration is shown in seconds but I need to format it 02h:30m:22s:15ms. For that I wrote a custom function in Crystal Report in the Formula Workshop editor as follows, but it looks like the syntax is not right (Error message on keyword Long: "A variable type (for example, 'String') is missing."). Can someone help?
Function GetTimeSpanString(seconds as Long) Dim ts As TimeSpan = TimeSpan.FromSeconds( seconds ); GetTimeSpan = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds) End Function
解决方案You could easily alter my ElapsedTime() function to meet your needs.
这篇关于Crystal报表将秒转换为Timespan格式的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!