Java将Long类型转换为时分秒

Java将Long类型转换为时分秒,第1张

Java将Long类型转换为时分秒

将秒转换为时分秒

    
    @Excel(name = "充电时间", width = 30)
    private Long chargeTime;
    private String chargeTimechargeTime;

    public String getChargeTimechargeTime() {
        if (chargeTime==null){
            return null;
        }
        //时
        Long hour = chargeTime / 60 / 60;
        //分
        Long minutes = chargeTime / 60 % 60;
        //秒
        Long remainingSeconds = chargeTime % 60;
        //判断时分秒是否小于10……
        if (hour < 10 && minutes < 10 && remainingSeconds < 10){
            chargeTimechargeTime = "0" + hour + ":" + "0" + minutes + ":" + "0" + remainingSeconds;
        }else if (hour < 10 && minutes < 10){
            chargeTimechargeTime = "0" + hour + ":" + "0" + minutes + ":" + remainingSeconds;
        }else if (hour < 10 && remainingSeconds < 10){
            chargeTimechargeTime = "0" + hour + ":" + minutes + ":" + "0" + remainingSeconds;
        }else if (minutes < 10 && remainingSeconds < 10){
            chargeTimechargeTime = hour + ":" + "0" + minutes + ":" + "0" + remainingSeconds;
        }else if (hour < 10){
            chargeTimechargeTime = "0" + hour + ":" + minutes + ":" + remainingSeconds;
        }else if (minutes < 10){
            chargeTimechargeTime = hour + ":" + "0" + minutes + ":" + remainingSeconds;
        }else if (remainingSeconds < 10){
            chargeTimechargeTime = hour + ":" + minutes + ":" + "0" + remainingSeconds;
        }else {
            chargeTimechargeTime = hour + ":" + minutes + ":" + remainingSeconds;
        }
        return chargeTimechargeTime;
    }

    public void setChargeTimechargeTime(String chargeTimechargeTime) {
        this.chargeTimechargeTime = chargeTimechargeTime;
    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3979047.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-21
下一篇 2022-10-21

发表评论

登录后才能评论

评论列表(0条)

保存