c # timestamp conversion

  ///  <Summary> 
    /// Get timestamp
     ///  </ Summary> 
    ///  <Returns> </ Returns> 
    public  static  String the GetTimeSpan (System.DateTime Time) 
    { 
        Long TS = GetUnixTime (Time);
         return TS .ToString (); 
    } 

    ///  <Summary>   
    /// the DateTime Unix time stamp format to format  
     ///  </ Summary> 
    ///  <param name = "time"> time </ param>   
    // /  <Returns> Long </ Returns>   
    public  static  Long GetUnixTime (System.DateTime Time)DateTime time)
    {
        The startTime System.DateTime = TimeZone.CurrentTimeZone.ToLocalTime ( new new System.DateTime ( 1970 , . 1 , . 1 , 0 , 0 , 0 , 0 ));
         Long T = (time.Ticks - startTime.Ticks) / 10000 ;    // addition 10000 adjusted to 13       
        return T; 
    } 
    ///  <Summary>         
    /// the timestamp Unix time format into C #      
     ///  </ Summary> 
    ///  <param name = "timeSpan"> </ param>         
    / //  <Returns> </ Returns>         
    public  static DateTime GetDateTimeFromUnix(string timeSpan)
    {
        DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
        long lTime = long.Parse(timeSpan + "0000");
        TimeSpan toNow = new TimeSpan(lTime);
        return dtStart.Add(toNow);
    }

/// <Summary>
/// creation time
/// </ Summary>
public String {createTime GET; SET;}

public DateTime _createTime {
get
{
if (string.IsNullOrEmpty(this.createTime))
return DateTime.MinValue;
return TimerTool.GetDate

 ///  <Summary> 
        /// The byte length to intercept the string
         ///  </ Summary> 
        /// <param name = "origStr"> Original string </ param> 
        /// <param name = " length "> extract the first length bytes </ param> 
        ///  <Returns> </ Returns> 
        public  static String CutByteString ( String origStr, int length) 
        { 
            byte [] bytes = Encoding.Unicode.GetBytes (origStr);
             int = n- 0 ; //   indicates the current number of bytes 
            int I = 0 ;//   to the number of bytes taken 
            for(; I <bytes.GetLength ( 0 ) && n-<length; I ++ ) 
            { 
                //   even position, such as 0,2,4, etc., for the first byte UCS2 code byte two 
                IF (I% 2 == 0 ) 
                { 
                    n ++; //   at UCS2 first byte plus n. 1 
                }
                 the else 
                { 
                    //   when UCS2 code second byte is greater than 0, the character is UCS2 characters, a character count two bytes 
                    IF (bytes [I]> 0 ) 
                    { 
                        n- ++ ; 
                    } 
                } 
            } 
            //  If i is odd, processing into even 
            IF (i% 2 == . 1 ) 
            { 
                //   when the character is UCS2 characters, kanji remove this truncated half 

                IF (bytes [i]> 0 ) 
                    i = i - . 1 ; 

                / /   the UCS2 character is a letter or number, the reserved character is 
                the else 
                    I = I + . 1 ; 
            } 
            return Encoding.Unicode.GetString (bytes, 0 , I); 
        } 

   var countlen = System.Text.Encoding.Default.GetByteCount (LocalDataManager .Instance.UserModel.student.name); 
                NameText.text= countlen > 12 ? CutByteString(LocalDataManager.Instance.UserModel.student.name, 12) : LocalDataManager.Instance.UserModel.student.name;

 

TimeFromUnix(this.createTime);
}
}

Guess you like

Origin www.cnblogs.com/DSC1991/p/11593338.html