zoukankan      html  css  js  c++  java
  • go 格式化秒 running

    package main
    
    import (
    	"fmt"
    )
    func SecondFormat(diffSec int) (timeStr string) {
    	if diffSec <= 60 {
    		//多少秒
    		timeStr = fmt.Sprintf("%d秒", diffSec)
    	} else if diffSec > 60 && diffSec < 3600 {
    		minute := diffSec / 60
    		second := diffSec % 60
    		//多少分
    		timeStr = fmt.Sprintf("%d分%d秒", minute, second)
    	} else if diffSec > 3600 && diffSec < 86400 {
    		//多少小时
    		hour := diffSec / 3600
    		minute := diffSec % 3600 / 60
    		second := diffSec % 3600 % 60
    		timeStr = fmt.Sprintf("%d小时%d分%d秒", hour, minute, second)
    	} else if diffSec > 86400 && diffSec < 86400*30 {
    		//多少天
    		day := diffSec / 86400
    		hour := diffSec % 86400 / 3600
    		minute := diffSec % 86400 % 3600 / 60
    		second := diffSec % 86400 % 3600 % 60
    		timeStr = fmt.Sprintf("%d天%d小时%d分%d秒", day, hour, minute, second)
    
    	}
    	return
    }
    func main() {
    	fmt.Println(SecondFormat(10))
    	fmt.Println(SecondFormat(60))
    	fmt.Println(SecondFormat(61))
    	fmt.Println(SecondFormat(3601))
    	fmt.Println(SecondFormat(86403))
    }
    

      

  • 相关阅读:
    swift
    swift
    swift
    swift
    swift
    swift
    swift
    swift
    Swift
    Nginx 访问控制
  • 原文地址:https://www.cnblogs.com/zxqblogrecord/p/15559718.html
Copyright © 2011-2022 走看看