java - Java 中的 C# Timespan 等价物?

标签 java timespan

<分区>

我正在尝试将以下 C# 代码转换为 Java。我在转换它时遇到困难。任何人都可以向我推荐一种使用 Java 进行此操作的简单方法。

 DateTime StartDate = new DateTime(PWUpdatedOn.Year, 01, 01);
 TimeSpan ts = new TimeSpan(PWUpdatedOn.Ticks - StartDate.Ticks);
 //Response.Write(ts.Days+1); 
 days = ts.Days + 1;
 lngN = 0;

 PWUpdatedOn.Year = 2016 // current year

最佳答案

作为Jigar Joshi在另一个Question中回答.

Interval from JodaTime will do..

A time interval represents a period of time between two instants. Intervals >are inclusive of the start instant and exclusive of the end. The end instant is always greater than or equal to the start instant. Intervals have a fixed millisecond duration. This is the difference between the start and end instants. The duration is represented separately by ReadableDuration. As a result, intervals are not comparable. To compare the length of two intervals, you should compare their durations.

An interval can also be converted to a ReadablePeriod. This represents the difference between the start and end points in terms of fields such as years and days.

Interval is thread-safe and immutable.

关于java - Java 中的 C# Timespan 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40716232/

相关文章:

java - 在 Java Swing 中禁用时如何调整字段的不透明度

java - 选择时的组合框

java - map 上的条件减少计数器以控制 map 输出

java - 已编译的 Groovy 类 - GC

javascript - 如何将时间跨度字符串解析为小时、分钟?

c# - 处理和存储耗时

c# - 多个 TimeSpan 的总和

java - 更改小部件样式的单个元素

vb.net - 如何在 VB.NET 中使用 TimeSpan 获取包含的总小时数

C# 将多个文本框的时间相加