Java小方法

    /**
     * 计算百分比.
     * @param dividend 被除数
     * @param divisor 除数
     * @return 结果
     */
    private String getPercent(long dividend, long divisor) {
        NumberFormat format = NumberFormat.getPercentInstance();
        format.setMinimumFractionDigits(2);
        if (divisor == 0) {
            return format.format(0.0);
        } else {
            return format.format((double) dividend / divisor);
        }
    }

 

    /**
     * 获取一周前的日期10位时间戳.
     * @return 10位时间戳
     */
    private long timeStamp() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -7);
        return calendar.getTimeInMillis() / 1000;
    }
                                                                                                                      来个链接:JAVA获取时间戳,哪个更快

 

posted @ 2016-02-24 15:42  ForeverLover  阅读(263)  评论(0编辑  收藏  举报