Exemple #1
0
    public static string ConvertTime(float time, ConvertTimeType format)
    {
        int    horas      = Mathf.FloorToInt(time / 3600);
        int    minutos    = Mathf.FloorToInt((time - horas * 3600) / 60);
        int    segundos   = Mathf.FloorToInt((time - horas * 3600 - minutos * 60));
        float  centesimos = Mathf.FloorToInt((time - Mathf.Floor(time)) * 100);
        string reth       = horas.ToString();
        string retm       = minutos.ToString();
        string rets       = segundos.ToString();
        string retc       = centesimos.ToString();

        if (horas < 10)
        {
            reth = "0" + reth;
        }
        if (minutos < 10)
        {
            retm = "0" + retm;
        }
        if (segundos < 10)
        {
            rets = "0" + rets;
        }
        if (centesimos < 10)
        {
            retc = "0" + retc;
        }

        string ret = "";

        if (format == ConvertTimeType.hmsc)
        {
            ret = reth + ":" + retm + ":" + rets + ":" + retc;
        }
        else if (format == ConvertTimeType.hms)
        {
            ret = reth + ":" + retm + ":" + rets;
        }
        else if (format == ConvertTimeType.msc)
        {
            ret = retm + ":" + rets + ":" + retc;
        }
        else if (format == ConvertTimeType.ms)
        {
            ret = retm + ":" + rets;
        }
        else if (format == ConvertTimeType.sc)
        {
            ret = rets + ":" + retc;
        }
        else if (format == ConvertTimeType.s)
        {
            ret = rets;
        }
        return(ret);
    }
Exemple #2
0
        int convertTimeType(int input, ConvertTimeType cType)
        {
            switch (cType)
            {
            case ConvertTimeType.MMSS2SEC_ONLY:
                return((input / 100) * 60 + (input % 100));

            case ConvertTimeType.SEC_ONLY2MMSS:
                return((input / 60) * 100 + (input % 60));

            default:
                break;
            }
            return(-1);
        }
Exemple #3
0
    // ############################################################################################ // Converte um float em formato de numeros reais
    public static string ConvertRealTime(float time, ConvertTimeType formato)
    {
        // @method author: Pedro de Souza
        int    horas      = Mathf.FloorToInt(time / 3600);
        int    minutos    = Mathf.FloorToInt((time - horas * 3600) / 60);
        int    segundos   = Mathf.FloorToInt((time - horas * 3600 - minutos * 60));
        float  centesimos = Mathf.FloorToInt((time - Mathf.Floor(time)) * 100);
        string reth       = horas.ToString();
        string retm       = minutos.ToString();
        string rets       = segundos.ToString();
        string retc       = centesimos.ToString();

        //filtro para o zero
        if (time <= 0)
        {
            reth = "0";
            retm = "0";
            rets = "0";
            retc = "0";
        }

        if (horas < 10)
        {
            reth = "0" + reth;
        }
        if (minutos < 10)
        {
            retm = "0" + retm;
        }
        if (segundos < 10)
        {
            rets = "0" + rets;
        }
        if (centesimos < 10)
        {
            retc = "0" + retc;
        }

        string ret = "";

        if (formato == ConvertTimeType.hmsc)
        {
            ret = reth + ":" + retm + ":" + rets + ":" + retc;
        }
        else if (formato == ConvertTimeType.hms)
        {
            ret = reth + ":" + retm + ":" + rets;
        }
        else if (formato == ConvertTimeType.hm)
        {
            ret = reth + ":" + retm;
        }
        else if (formato == ConvertTimeType.msc)
        {
            ret = retm + ":" + rets + "," + retc;
        }
        else if (formato == ConvertTimeType.ms)
        {
            ret = retm + ":" + rets;
        }
        else if (formato == ConvertTimeType.sc)
        {
            ret = rets + ":" + retc;
        }
        else if (formato == ConvertTimeType.s)
        {
            ret = rets;
        }
        return(ret);
    }