时间转换

时间转换
public static long DateTimeToTime_t(DateTime dateTime)
        {
            long time_t;
            DateTime dt1 = new DateTime(1970, 1, 1, 0, 0, 0);
            TimeSpan ts = dateTime - dt1;
            time_t = ts.Ticks / 10000000 - 28800;//本地时间8小时为28800秒
            return time_t;
        }



public static Int64 LocalTimeToTimeT(DateTime stLocalTime)
        {
            Int64 int64time = stLocalTime.ToFileTime();
            int64time -= 0x19db1ded53e8000;
/* Subtract the value for 1970-01-01 00:00 (UTC) */
            int64time /= 10000000;
 /* Convert to seconds. */

            return int64time;
        }


public static DateTime Int64ToLocalTime(Int64 int64Time)
        {
            int64Time *= 10000000;
            int64Time += 0x19db1ded53e8000;
            return DateTime.FromFileTime(int64Time).ToLocalTime();
        }

你可能感兴趣的:(转换)