Here you can find the source of timeToString(long time)
Parameter | Description |
---|---|
time | a parameter |
public static String timeToString(long time)
//package com.java2s; //License from project: Apache License public class Main { public static final long ONE_WEEK_IN_MILISECONDS = 604800000L; public static final long ONE_DAY_IN_MILISECONDS = 86400000L; public static final long ONE_HOUR_IN_MILISECONDS = 3600000L; public static final long ONE_MINUTE_IN_MILISECONDS = 60000L; /**/*from www .ja va2s .c o m*/ * * @param time * @return */ public static String timeToString(long time) { String returnTime = ""; long temp; if (time / ONE_WEEK_IN_MILISECONDS > 0) { temp = time / ONE_WEEK_IN_MILISECONDS; returnTime += temp + "w "; returnTime += (time - temp * ONE_WEEK_IN_MILISECONDS) / ONE_DAY_IN_MILISECONDS + "d"; } else if (time / ONE_DAY_IN_MILISECONDS > 0) { temp = time / ONE_DAY_IN_MILISECONDS; returnTime += temp + "d "; returnTime += (time - temp * ONE_DAY_IN_MILISECONDS) / ONE_HOUR_IN_MILISECONDS + "h"; } else if (time / ONE_HOUR_IN_MILISECONDS > 0) { temp = time / ONE_HOUR_IN_MILISECONDS; returnTime += temp + "h "; returnTime += (time - temp * ONE_HOUR_IN_MILISECONDS) / ONE_MINUTE_IN_MILISECONDS + "m"; } else if (time / ONE_MINUTE_IN_MILISECONDS >= 0) { returnTime += time / ONE_MINUTE_IN_MILISECONDS + "m"; } else { returnTime = "0m"; } return returnTime; } }