7 个解决方案
#1
TimeSpan ts = dt - new DateTime(1970, 1, 1);
int i = ts.TotalMilliseconds;
int i = ts.TotalMilliseconds;
#2
TimeSpan ts = DateTime.Now - DateTime.Parse("1970-1-1");
double d = ts.TotalMilliseconds;
把DateTime.Now换成你的日期就可以了。
double d = ts.TotalMilliseconds;
把DateTime.Now换成你的日期就可以了。
#3
(DateTime.Now-new DateTime(1970,1,1).TotalMilliseconds
#4
TimeSpan ts = dt - new DateTime(1970, 1, 1);
int i = (int)ts.TotalMilliseconds;
int i = (int)ts.TotalMilliseconds;
#5
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long now = DateTime.Now.Ticks;
long begin = DateTime.Parse("2000-1-1 0:0:0").Ticks;
long timeSpan = (long)Math.Abs(now - begin);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
{
long now = DateTime.Now.Ticks;
long begin = DateTime.Parse("2000-1-1 0:0:0").Ticks;
long timeSpan = (long)Math.Abs(now - begin);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
#6
贴错了 -_-
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long timeSpan = (long)Math.Abs(dateTime1.Ticks - dateTime2.Ticks);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long timeSpan = (long)Math.Abs(dateTime1.Ticks - dateTime2.Ticks);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
#7
up!
#1
TimeSpan ts = dt - new DateTime(1970, 1, 1);
int i = ts.TotalMilliseconds;
int i = ts.TotalMilliseconds;
#2
TimeSpan ts = DateTime.Now - DateTime.Parse("1970-1-1");
double d = ts.TotalMilliseconds;
把DateTime.Now换成你的日期就可以了。
double d = ts.TotalMilliseconds;
把DateTime.Now换成你的日期就可以了。
#3
(DateTime.Now-new DateTime(1970,1,1).TotalMilliseconds
#4
TimeSpan ts = dt - new DateTime(1970, 1, 1);
int i = (int)ts.TotalMilliseconds;
int i = (int)ts.TotalMilliseconds;
#5
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long now = DateTime.Now.Ticks;
long begin = DateTime.Parse("2000-1-1 0:0:0").Ticks;
long timeSpan = (long)Math.Abs(now - begin);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
{
long now = DateTime.Now.Ticks;
long begin = DateTime.Parse("2000-1-1 0:0:0").Ticks;
long timeSpan = (long)Math.Abs(now - begin);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
#6
贴错了 -_-
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long timeSpan = (long)Math.Abs(dateTime1.Ticks - dateTime2.Ticks);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
public static long GetTimeSpan(string part, DateTime dateTime1, DateTime dateTime2)
{
long timeSpan = (long)Math.Abs(dateTime1.Ticks - dateTime2.Ticks);
switch(part.ToLower())
{
case "f":
timeSpan = timeSpan / TimeSpan.TicksPerMillisecond;
break;
case "s":
timeSpan = timeSpan / TimeSpan.TicksPerSecond;
break;
case "m":
timeSpan = timeSpan / TimeSpan.TicksPerMinute;
break;
case "h":
timeSpan = timeSpan / TimeSpan.TicksPerHour;
break;
case "d":
timeSpan = timeSpan / TimeSpan.TicksPerDay;
break;
default:
timeSpan = 0;
break;
}
return timeSpan;
}
#7
up!