Is there something like TimeSpan in android development?

后端 未结 6 499
盖世英雄少女心
盖世英雄少女心 2021-01-12 05:29

I need to know if there is something like a timespan in android development?

in C# there is something like and I like to use it in two ways:

  1. generate a
6条回答
  •  醉梦人生
    2021-01-12 06:18

    You can easily get the "TimeSpan" in milliseconds. To convert milliseconds to a formatted one, you can do a little fast and elegant calculation in your function like this,

    public static String GetFormattedTimeSpan(final long ms) {
        long x = ms / 1000;
        long seconds = x % 60;
        x /= 60;
        long minutes = x % 60;
        x /= 60;
        long hours = x % 24;
        x /= 24;
        long days = x;
    
        return String.format("%d days %d hours %d minutes %d seconds", days, hours, minutes, seconds);
    }
    

提交回复
热议问题