Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static HashMap<String, Integer> getDifferences(Date begin, Date end) {
- HashMap<String, Integer> output = new HashMap<>();
- long diff = end.getTime() - begin.getTime();
- output.put("s", (int) diff / 1000 % 60);
- output.put("m", (int) diff / (60 * 1000) % 60);
- output.put("h", (int) diff / (60 * 60 * 1000) % 24);
- output.put("d", (int) diff / (24 * 60 * 60 * 1000));
- return output;
- }
- public static String clockFormat(HashMap<String, Integer> input) {
- String output = "";
- ArrayList<String> units = new ArrayList<>();
- for (String key : input.keySet()) {
- if (input.get(key) > 10) {
- units.add("0" + input.get(key));
- } else {
- units.add(input.get(key) + "");
- }
- }
- for (String unit : units) {
- if (!output.equals("")) {
- output = output + ":" + unit;
- } else {
- output = unit;
- }
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement