package com.swago.baseswago.util

import java.text.SimpleDateFormat
import java.util.*

/**
 *@date 2021/11/28 21:50
 *description:
 */
object TimeUtil {


    /**
     * 秒转化成分秒
     */
    fun convertMinSecond(time: Long): String {
        var convertTime = ""
        var min = 0
        var sec = 0
        if (time <= 0) {
            return "00:00"
        } else {
            min = (time / 60).toInt()
            sec = (time % 60).toInt()
            convertTime = unitFormat(min) + ":" + unitFormat(sec)
        }

        return convertTime
    }


    private fun unitFormat(i: Int): String {
        return if (i in 0..9) {
            "0$i"
        } else {
            i.toString()
        }
    }


    /**
     * 时间戳转化成年
     */
    fun convertYear(time: Long):Int {
        val date = Date(time)
        val format = SimpleDateFormat("yyyy")
        return format.format(date).toInt()
    }
}