Calculate how many hours since the epoch?

it's a simple question, but I'm nervous about how complicated the answer might be. I want to know in my application, how many hours have passed since the epoch. More specifically, I want to know "how many times since the epoch has a GMT clock ended in :00" Normally I would just do: number_of_seconds_since_epoch / 3600 but I'm not really sure if an hour is exactly 3600

计算时代以来多少小时?

这是一个简单的问题,但我对答案的复杂程度感到紧张。 我想在我的应用程序中知道,从这个时代开始已经过去了多少小时。 更具体地说,我想知道“从历元开始有多少次GMT时钟以00结尾” 通常我会这样做: number_of_seconds_since_epoch / 3600 但我不确定一小时是不是3600秒。 我一直听到地球一直在减速和加速,以及闰年如何做奇怪的事情等等。 任何人都可以使用任何语言向我展示正确的方法吗? 谢谢! 像许多计算机系

Find the exact difference between two (Joda Time) DateTime objects in java

I am given two dates (one of which is the present) and need to find the difference between the two. My code is giving me bad output (sometimes even negative). I have tried using the Months, Days, Seconds, Hours, and Years classes and appropriate between methods with no luck. Edit: Went back to my original code but without Duration. @Basil Bourque posted a great solution but I just don't

在java中查找两个(Joda Time)DateTime对象之间的确切区别

我给了两个日期(其中之一是现在),并且需要找出两者之间的区别。 我的代码给了我不好的输出(有时甚至是负面的)。 我尝试过使用“月”,“日”,“秒”,“小时”和“年”类,并且在没有运气的方法之间适当使用。 编辑:回到我的原始代码,但没有持续时间。 @Basil Bourque发布了一个很好的解决方案,但我只是没有足够的期限/持续时间经验以及从中动态格式化的所有经验。 解 public static String formattedTime(DateTime d){

> easier way?

hi i'm asking myself if there is an easier way to get the number of days between two dates. I want only the days, without looking at the hours or minutes. Therefore if today is monday, and the date wich i want to compare is on wednesday, the days between are 2 (the time does not matter) Therefore i use this code: Calendar c = Calendar.getInstance(); // Only the day:

>更简单的方法?

嗨,我问自己,如果有一个更简单的方法来获得两个日期之间的天数。 我只想要这些日子,而不需要看时间或分钟。 因此,如果今天是星期一,并且我想比较的日期是星期三,那么这两天之间的时间是2(时间无关紧要) 因此我使用这个代码: Calendar c = Calendar.getInstance(); // Only the day: c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0);

declaring a startdate & endate using joda time?

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers This int Days; Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays(); should be something like int dayCount = Days.daysBetween(start, end).getDays(); Because start and end are already LocalDate (s) and you want to save the result of the call. Also, you should only need one Easy

使用joda时间声明startdate&endate?

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 这个 int Days; Days.daysBetween(new LocalDate(start),new LocalDate(end)).getDays(); 应该是这样的 int dayCount = Days.daysBetween(start, end).getDays(); 因为start和end已经是LocalDate (s)并且您想保存呼叫的结果。 另外,您应该只需要一个 EasyReader实例。 而且,你需要添加 import org.joda.time.Days;

How to include start date in Joda Time daysBetween?

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers Actually Days.daysBetween(-,-) method just subtracts the start day from the end day. If you want to get the total no of days including the start day then you must have to minus 1 from the start date.

如何在Joda时间日期之间包含开始日期?

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 其实Days.daysBetween( - , - )方法只是从结束日期减去开始日期。 如果你想获得包括开始日在内的总天数,那么你必须从开始日期减去1。

Finding difference of days from start and end using joda?

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers Use Days Class of Joda Library Days days=Days.daysBetween(startDate.toLocalDate(), endDate.toLocalDate()).getDays(); int noOfDays=days.getDays(); As an alternative we can also ues Java 8 Date and Time API public void days_between_two_dates_in_java_with_java8 () { LocalDate startDate = Loc

使用joda从开始和结束找到天数差异?

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 使用Joda图书馆的Days Days Days days=Days.daysBetween(startDate.toLocalDate(), endDate.toLocalDate()).getDays(); int noOfDays=days.getDays(); 作为替代,我们也可以使用Java 8 日期和时间API public void days_between_two_dates_in_java_with_java8 () { LocalDate startDate = LocalDate.now().minusDays(1); LocalDate endDate

How to compare dates in Android app?

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers I would say it is not printing 1 but -1 . The compare function just compares two dates, it does not compute a time difference. Check the Joda Time documentation for more information. Also, I suggest you to read about the more general Java interface Comparator which is a fundamental unit of th

如何比较Android应用中的日期?

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 我会说它不打印1而是-1 。 compare函数只是比较两个日期,它不计算时间差。 查看Joda Time文档以获取更多信息。 另外,我建议你阅读更通用的Java接口Comparator ,它是Java语言的基本单元。 我从未使用乔达时间,但我在这里读到,解决您的问题可能是 Days.daysBetween(actionDate.toDateMidnight(), DateTime.now().toDateMidnight()).getDays()

Calculating the number of days between two dates using joda time api

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers Use this Days.daysBetween(intdt.toLocalDate(), targetDt.toLocalDate()).getDays() The LocalDate class does not store or represent a time or time-zone. Instead, it is a description of the date. SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); String inputString1 = "23 01 1997";

使用joda time api计算两个日期之间的天数

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 用这个 Days.daysBetween(intdt.toLocalDate(), targetDt.toLocalDate()).getDays() LocalDate类不存储或表示时间或时区。 相反,它是对日期的描述。 SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); String inputString1 = "23 01 1997"; String inputString2 = "27 04 1997"; try { Date date1 = myFormat.parse(inputS

Expiration Date control program

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers Java has a built in date class which has many problematic issues, so it is not worth using. Instead, the Joda-Time api offers a reliable Java date and time API. The API and some information about it can be found at http://www.joda.org/joda-time/. A similar question has been asked already, an

到期日期控制程序

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 Java有一个内置的date类,它有很多问题,所以不值得使用。 相反,Joda-Time api提供了可靠的Java日期和时间API。 API和一些关于它的信息可以在http://www.joda.org/joda-time/找到。 一个类似的问题已经被问到,并且在Joda-Time的两个日期之间的天数中可以找到一些答案和一些示例代码。 对于你的情况,使用默认构造函数实例化一个新的时间会给

difference in months between two dates

This question already has an answer here: Number of days between two dates in Joda-Time 6 answers Changing the first date to 2015-02-02, Joda correctly returns 1 month: DateTime date1 = new DateTime().withDate(2015, 2, 2); DateTime date2 = new DateTime().withDate(2015, 1, 1); System.out.println(Months.monthsBetween(date2, date1).getMonths()); // Returns 1. So my guess is that because you d

两个日期之间的月差

这个问题在这里已经有了答案: Joda-Time中的两个日期之间的天数6个答案 将第一个日期更改为2015-02-02,Joda正确返回1个月: DateTime date1 = new DateTime().withDate(2015, 2, 2); DateTime date2 = new DateTime().withDate(2015, 1, 1); System.out.println(Months.monthsBetween(date2, date1).getMonths()); // Returns 1. 所以我的猜测是,因为你没有提供时间部分,所以Joda无法准确确定2015-01-01 date2所指的