新变量中使用startDate和endDate定义自己的日期间隔

新变量中使用startDate和endDate定义自己的日期间隔

本文介绍了在新变量中使用startDate和endDate定义自己的日期间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的动态日期是时间戳参数timestamp1,timestamp2的参数,我正在努力使用日期计算来定义自己的条形图系列。 ,timestamp3,timestamp4wheras我想创建间隔



interval1:timestamp1和timestamp2之间的日期



interval2:timestamp3和timestamp4之间的日期。



我必须添加到我的变量的表达式才能拥有我的条形图系列的两个时间间隔?我完全失去了这个问题。

解决方案

正如David Wallace所言,你应该看看。并用joda和interval搜索其他问题。



2.3是一个用于处理日期时间计算的开源库。 Joda-Time启发了Java 8中构建的java.time。*类的创建。



As 完全符合您的需求:以智能的方式处理一对开始日期,精通时区和和其他异常情况。



DateTime Now(DateTimeZone.forID(Europe / Paris));

  //巴黎当前时刻
间隔间隔=新间隔(现在,now.plusHours(8));

要描述时间跨度(已过),请参阅课程。他们可以用人类语言(法语,英语等)描述几个月 - 几十分钟的时间。他们可以描述的ISO 8601格式的跨度。






进一步提示...



为了及时表示一个时刻,请使用类。



当需要与只知道java.util.Date的其他类交互时,调用 toDate 方法。



请注意,应该避免使用java.util.Date/Calendar类,因为它们设计和实现不当。 Java 8将用上面提到的java.time *类替代它们。


I am struggling with a date calculation to define my own range for a bar chart series.

My dynamic dates are parameters the timestamp parameters "timestamp1", "timestamp2", "timestamp3", "timestamp4" wheras I want to create the intervals

interval1: days between "timestamp1" and "timestamp2"

interval2: days between "timestamp3" and "timestamp4".

What is the expression that I have to add to my variables in order to have two time intervals for my bar chart series? I am completely lost with this issue.

解决方案

As commented by David Wallace, you should look at the question Calculating the Difference Between Two Java Date Instances. And search for other questions with "joda" and "interval".

Joda-Time 2.3 is an open-source library for handling date-time calculations. Joda-Time has inspired the creation of the java.time.* classes being built into Java 8.

As discussed in the doc, Joda-Time offers the Interval class for exactly your needs: Handling a pair of start-stop dates in an intelligent manner, savvy with time zones and Daylight Savings Time (DST) and other anomalies.

DateTime now = DateTime.now( DateTimeZone.forID( "Europe/Paris" ) );  // Current moment in Paris.
Interval interval = new Interval( now, now.plusHours( 8 ) );

To describe the time span (elapsed), see the Period and Duration classes. They can describe the years-months-days-hours-minutes-seconds in human language (French, English, etc.). They can describe the span in ISO 8601 format of PnYnMnDTnHnMnS.


Further tips…

For representing a single moment in time, use the DateTime class.

When necessary to interact with other classes that know only java.util.Date, call the toDate method.

Note that you should avoid using the java.util.Date/Calendar classes, as they are badly designed and implemented. Java 8 will supplant them with the java.time.* classes mentioned above.

这篇关于在新变量中使用startDate和endDate定义自己的日期间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 00:34