using System;

namespace ConsoleApplication8
{
class Program
{
/*
static void Main(string[] args)
{
DateTime dt = new DateTime();
Console.WriteLine(dt);//基督元年
Console.WriteLine(DateTime.MinValue);
Console.WriteLine(DateTime.MaxValue);
dt = DateTime.Today;
Console.WriteLine(dt);
dt = DateTime.UtcNow;
Console.WriteLine(dt);

dt = DateTime.Now;
Console.WriteLine(dt);
Console.WriteLine(dt.Year);
Console.WriteLine(dt.Month);
Console.WriteLine(dt.Day);
Console.WriteLine(dt.Date);//这个跟上面的DateTime.Today相等

Console.WriteLine(dt.Hour);
Console.WriteLine(dt.Minute);
Console.WriteLine(dt.Second);

Console.WriteLine(dt.DayOfYear);
Console.WriteLine(dt.DayOfWeek);
Console.WriteLine(dt.TimeOfDay);

Console.WriteLine(dt.Kind);//是基于本地时间、协调通用时间 (UTC),还是两者皆否
Console.WriteLine(dt.Millisecond);//毫秒部分
Console.WriteLine(dt.Ticks);
}
*/
static void Main(string[] args)
{
Console.WriteLine(ConvertDateTimeInt(DateTime.Now));
Console.WriteLine(ConvertIntDateTime(ConvertDateTimeInt(DateTime.Now)));
}
public static DateTime ConvertIntDateTime(double d)
{
DateTime time = DateTime.MinValue;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
time = startTime.AddSeconds(d);
return time;
}
/// <summary>
/// 将c# DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>double</returns>
public static double ConvertDateTimeInt(DateTime time)
{
double intResult = 0;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
intResult = (time - startTime).TotalSeconds;
return intResult;
}
}
}