Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * @param duration : 302000
     * @return 5:02
     */
    public static String formatDuration(String duration) {
        String result = duration;
        try {
            long du = Integer.parseInt(result) / 1000;
            result = String.format("%02d:%02d", du / 60, du % 60);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static String formatDuration(int duration) {
        String result = "00:00";
        try {
            long du = duration / 1000;
            result = String.format("%02d:%02d", du / 60, du % 60);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return result;
    }
}