Jak znaleźć różnicę między dwoma datami czasu Joda w minutach
Poniżej jest metoda, którą napisałem:
public List<Map<String, Object>> loadNotYetInEmployee(int shift, Date date,
int transitionVal, String type, User user) {
DateTime datetime = new DateTime(date);
datetime = datetime
.plus(Period.minutes(shiftTiming.getSession1InTime()));
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
sql = SqlMapUtils.getSql("attendance.attendancestatus.latein",
parameters);
result = getJdbcTemplate().queryForList(sql);
for (int i = 0; i < result.size(); i++) {
Date punchInTime = (Date) result.get(i).get("punchtime");
DateTime punchTime = new DateTime(punchInTime);
}
return result;
}
Teraz z mojej metody widać, że mam Joda-czas DateTime obiekt w obiekcie o nazwie datetime
i z mojego wyniku otrzymuję jeden znacznik czasu, który konwertuję na jodatime punchTime
. Teraz chcę dowiedzieć się różnicy między tymi dwoma datami, jak to zrobić?
Z góry dzięki
120
Author: Ortomala Lokni, 2012-10-12
3 answers
To da Ci różnicę między dwoma obiektami DateTime w milisekundach:
DateTime d1 = new DateTime();
DateTime d2 = new DateTime();
long diffInMillis = d2.getMillis() - d1.getMillis();
65
Author: alfredaday,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-01 07:49:03
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-01 07:49:03
Coś w tym stylu...
DateTime today = new DateTime();
DateTime yesterday = today.minusDays(1);
Duration duration = new Duration(yesterday, today);
System.out.println(duration.getStandardDays());
System.out.println(duration.getStandardHours());
System.out.println(duration.getStandardMinutes());
Które wyjścia
1
24
1440
Lub
System.out.println(Minutes.minutesBetween(yesterday, today).getMinutes());
Czyli raczej to, czego szukasz
411
Author: MadProgrammer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-01 18:46:13
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-01 18:46:13
Coś w tym stylu...
Minutes.minutesBetween(getStart(), getEnd()).getMinutes();
1
Author: Carlos Andres Chaguendo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-06 20:02:51
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-06 20:02:51