c# dateTimePicker控件 DateTime时间格式 与 Unix时间戳格式(1970.1.1至今的秒数) 互相转换

MessageBox.Show(dateTimePicker1.Text);
MessageBox.Show(dateTimePicker1.Value.ToString());

将c# DateTime时间格式转换为Unix时间戳格式(1970.1.1至今的秒数)

double intResult = 0;
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
intResult = (dateTimePicker1.Value - startTime).TotalSeconds;
MessageBox.Show(intResult.ToString());

将Unix时间戳转换为DateTime类型时间

DateTime time = DateTime.MinValue;
startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
time = startTime.AddSeconds(intResult);
MessageBox.Show(time.ToString());

你可能感兴趣的:(C#)