各类数据类型的转换类

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// string扩展方法
/// </summary>
public static class KTOString  {

    /// <summary>
    /// 扩展--string 转int
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static int Toint(this string str)
    {
        return Convert.ToInt32(str);
    }

    public static int Toint(this long log)
    {
        return Convert.ToInt32(log);
    }
    /// <summary>
    /// 扩展---string转
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static float Tofloat(this string str)
    {
        return float.Parse(str);
    }
    /// <summary>
    /// 扩展---string转long
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static long Tolong(this string str)
    {
        return long.Parse(str);
    }
    /// <summary>
    /// 扩展---enum转byte
    /// </summary>
    /// <param name="eEnum"></param>
    /// <returns></returns>
    public static byte Tobyte (this Enum eEnum)
    {
        return Convert.ToByte(eEnum);
    }
    /// <summary>
    /// 扩展---enum转short
    /// </summary>
    /// <param name="eEnum"></param>
    /// <returns></returns>
    public static short ToShort(this Enum eEnum)
    {
        return Convert.ToInt16(eEnum);
    }
    /// <summary>
    /// 扩展---转string
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public static string Tostring(this object obj)
    {
        return obj.ToString();
    }
    /// <summary>
    /// 时间戳转C#时间
    /// </summary>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    public static string Todata(this long timeStamp)
    {
        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
        DateTime dt = startTime.AddMilliseconds(timeStamp);
        return dt.ToString("MM/dd HH:mm");
    }
}

 

posted @ 2018-10-19 11:29  扎北强子  阅读(290)  评论(0编辑  收藏  举报