简体   繁体   English

如何在Birt报告中将字符串转换为时间/分钟?

[英]How to convert a string to time/minutes in Birt report?

I have string value stored in database say "4:30 PM" and I am fetching it in Birt. 我在数据库中存储了字符串值“4:30 PM”,我在Birt中获取它。 I want to convert this value to minutes. 我想将此值转换为分钟。 Is there any method/way(In birt/database) to do that ? 是否有任何方法/方式(在birt /数据库中)这样做? (Other than splinting and adding) (除了夹板和添加)

PS : I want to find minutes difference between "4:30 PM" and 04:45 PM(IT STORED IN TIME). PS:我想找到“4:30 PM”和04:45 PM(IT STORED IN TIME)之间的分钟差异。

FYI : I am using Postgres database. 仅供参考:我正在使用Postgres数据库。

I agree with Frank comments, storing a string type to represent a Time value in a database is a very unefficient design. 我同意Frank的意见,存储一个字符串类型来表示数据库中的Time值是一种非常低效的设计。 However sometimes we can't change this easily. 但有时我们不能轻易改变这一点。 Here is how to parse a such format in BIRT. 以下是如何在BIRT中解析这种格式。

Create a computed column in the dataset, set "Time" as dataType and enter as expression: 在数据集中创建计算列,将“Time”设置为dataType并输入为expression:

var dateFormat = new java.text.SimpleDateFormat("hh:mm a",java.util.Locale.ENGLISH);
dateFormat.parse(row["timeString"]);

Where "timeStr" is of course the name of your time column in that string format. 其中“timeStr”当然是该字符串格式的时间列的名称。 If the dataset should handle large volumes, you could optimize this expression by intializing "dateFormat" only once in beforeOpen event. 如果数据集应处理大量卷,则可以通过在beforeOpen事件中初始化“dateFormat”一次来优化此表达式。

For the second question, Birt has a native static function to get a difference in minutes: 对于第二个问题,Birt有一个本机静态函数可以在几分钟内获得差异:

BirtDateTime.diffMinute(time1, time2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM