用于:将DateTime转换为Long数值 和 将Long数值转换为DateTime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using UnityEngine; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization void Start () { Debug.Log( ConvertLongToDateTime( 1493030300 ) ); Debug.Log( ConvertDateTimeToLong( System.DateTime.Now ) ); } private System.DateTime ConvertLongToDateTime( long timeStamp ) { System.DateTime dtStart = System.TimeZone.CurrentTimeZone.ToLocalTime( new System.DateTime( 1970, 1, 1 ) ); long lTime = long.Parse( timeStamp + "0000000" ); System.TimeSpan toNow = new System.TimeSpan( lTime ); return dtStart.Add( toNow ); } private long ConvertDateTimeToLong( System.DateTime time ) { System.DateTime startTime = System.TimeZone.CurrentTimeZone.ToLocalTime( new System.DateTime( 1970, 1, 1 ) ); return (long)( time - startTime ).TotalSeconds; } } |
- 本文固定链接: http://www.u3d8.com/?p=1112
- 转载请注明: 网虫虫 在 u3d8.com 发表过