本文整理汇总了C#中System.TimeSpan.Subtract方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.Subtract方法的具体用法?C# TimeSpan.Subtract怎么用?C# TimeSpan.Subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.Subtract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintDayStats
private static void PrintDayStats(IReadOnlyList<DateTime> dates)
{
var totalMinutesIn = new TimeSpan(0, 0, 0, 0);
var totalMinutesOut = new TimeSpan(0, 0, 0, 0);
DateTime lastDate = dates[0];
var isIn = false;
for (int i = 1; i < dates.Count; i++)
{
var instance = dates[i];
isIn = !isIn;
if (isIn)
{
totalMinutesIn = totalMinutesIn.Add(instance.Subtract(lastDate));
}
else
{
totalMinutesOut = totalMinutesOut.Add(instance.Subtract(lastDate));
}
lastDate = instance;
}
Console.WriteLine("Total minutes in: {0}, out: {1}, extra: {2}", totalMinutesIn, totalMinutesOut, totalMinutesIn.Subtract(Day));
_overtime = _overtime.Add(totalMinutesIn.Subtract(Day));
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
HyLonginLog hyLonginLog = new HyLonginLog();
DataTable dt = hyLonginLog.GetDataTableAllOnLine();
if (dt.Rows.Count > 0)
{
DateTime t1 = new DateTime();
DateTime t2 = DateTime.Now;
DateTime t3 = new DateTime();
double diff = 0;
double onlineTimeTotal = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
t1 = Convert.ToDateTime(dt.Rows[i]["hyUpateTime"].ToString());
t3 = Convert.ToDateTime(dt.Rows[i]["hyLoginTime"].ToString());
TimeSpan tt1 = new TimeSpan(t1.Ticks);
TimeSpan tt2 = new TimeSpan(t2.Ticks);
TimeSpan tt3 = new TimeSpan(t3.Ticks);
diff = Convert.ToDouble(tt2.Subtract(tt1).TotalMinutes.ToString());
onlineTimeTotal = Convert.ToDouble(tt2.Subtract(tt3).TotalMinutes.ToString());
if (diff >= 10)
{
hyLonginLog.id = dt.Rows[i]["id"].ToString();
hyLonginLog.hyLogoutTime = DateTime.Now.ToString();
hyLonginLog.hyNotOnLine = "1";
hyLonginLog.hyonlineTimeTotal = onlineTimeTotal.ToString("0.00");
hyLonginLog.UpdateLogOutTime();
}
}
}
}
示例3: Draw
public void Draw(SpriteBatch sb, int xlocation, TimeSpan currentTime)
{
if (!visible) return;
int stretch = 0;
float fadeOutAmt = 1.0f;
if (completed)
{
stretch = (int)(currentTime.Subtract(compSpan).TotalMilliseconds / 5); //magic numbers: 500 milliseconds to grow 50 pixels
fadeOutAmt = Math.Max((50.0f - stretch) / 50.0f , 0.0f);
//scoreColor.A = (byte)Math.Max((125 * fadeOutAmt), 0);
//scoreColor = scoreColor * Math.Max(fadeOutAmt, 0);
if (stretch > 50)
{
visible = false;
return;
}
}
double fadeIn = currentTime.Subtract(moveSpan).TotalMilliseconds + 1200.0f;
if (fadeIn < 0)
fadeOutAmt = (float)(800.0f + fadeIn) / 800.0f; //magic numbers!
if (GetMoveIcon() != null)
sb.Draw(GetMoveIcon(), new Rectangle(xlocation - stretch, GLOBALS.WINDOW_HEIGHT - (160 + stretch), 120 + (2 * stretch), GLOBALS.WINDOW_HEIGHT - (350 - (2 * stretch))), scoreColor * fadeOutAmt);
}
示例4: ApplyVelocity
public virtual float ApplyVelocity(TimeSpan from, TimeSpan to, TimeSpan totalDuration, float totalDistance)
{
if (from > totalDuration)
{
while (from > totalDuration)
{
from = from.Subtract(totalDuration);
to = to.Subtract(totalDuration);
}
}
else
{
if (to > totalDuration) to = totalDuration;
}
double scaleTime = ((double)totalDuration.TotalSeconds / (Right - Left));
float scaleDistance = totalDistance / (float)Area;
double l = Left + (double)from.TotalSeconds / scaleTime;
double r = Left + (double)to.TotalSeconds / scaleTime;
double distance = Integral(l, r);
float deltaDistance = scaleDistance * (float)distance;
return deltaDistance;
}
示例5: decidetime
private bool decidetime()
{
TimeSpan ts1 = new TimeSpan(dtpDate.Value.Ticks);
TimeSpan ts2 = new TimeSpan(dtpDate1.Value.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
if ((int)ts.Days > 31)
{
MessageBox.Show("跨月查询不能多于三十一天!", "提示", MessageBoxButtons.OK);
return false;
}
if ((dtpDate.Value.AddYears(1).Year == dtpDate1.Value.Year || dtpDate.Value.Year == dtpDate1.Value.Year) && ((dtpDate.Value.Month == dtpDate1.Value.Month) || (dtpDate.Value.AddMonths(1).Month == dtpDate1.Value.Month)))
{ }
else
{
MessageBox.Show("不能跨多月份查询!", "提示", MessageBoxButtons.OK);
return false;
}
if ((int)ts.Days > 31)
{
MessageBox.Show("跨月查询不能多于三十一天!", "提示", MessageBoxButtons.OK);
return false;
}
if (Convert.ToDateTime(dtpDate1.Value) > DateTime.Now)
{
dtpDate1.Value = DateTime.Now;
}
if (Convert.ToDateTime(dtpDate.Value).Date > Convert.ToDateTime(dtpDate1.Value).Date)
{
MessageBox.Show("开始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
return true;
}
示例6: Main
static void Main(string[] args)
{
//微软MSMQ消息队列与WCF离线操作
//HTTP NetMsmqBinding_IWCFMSMQService
WCFMSMQServiceClient wcfServiceProxy = new WCFMSMQServiceClient("NetMsmqBinding_IWCFMSMQService");
//通过代理调用SayHello服务,这里及时服务调用服务失败,消息会发送到队列里进行缓存。
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks);
for (int i = 0; i < 100000; i++)
{
Console.WriteLine("xiaopotian");
wcfServiceProxy.SayHelloMSMQ("xiaopotian");
}
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration();
//string a = ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒";
Console.WriteLine(ts.Milliseconds);
//Thread.Sleep(2000);//客户端休眠两秒,继续下一次调用
//Console.WriteLine("WCF 2 Call at:{0}", DateTime.Now);
//wcfServiceProxy.SayHelloMSMQ("Frank Xu");
//Thread.Sleep(2000);//客户端休眠两秒,继续下一次调用
//Console.WriteLine("WCF 3 Call at:{0}", DateTime.Now);
//wcfServiceProxy.SayHelloMSMQ("Frank Xu Lei");
//For Debug
Console.WriteLine("Press any key to continue");
Console.Read();
}
示例7: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string htmlstring = "";
News spfNews = new News();
int RecordCount = spfNews.LoadSpfNews();
if (RecordCount > 0)
{
for (int i = 0; i < RecordCount; ++i)
{
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts2 = new TimeSpan(spfNews.SpfNews[i].updateTime.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
// string strA = null;
// if ( ts.Days/365 > 0 ) strA = (ts.Days/365).ToString() + " 年之前";
// else
// {
// if ( ts.Days/30 > 0 ) strA = (ts.Days/30).ToString() + " 月之前";
// else
// {
// if ( ts.Days > 0 ) strA = ts.Days.ToString() + " 天之前";
// else
// {
// if ( ts.Hours > 0 ) strA = ts.Hours.ToString() + " 小时之前";
// else
// {
// if ( ts.Minutes > 0 ) strA = ts.Minutes.ToString() + " 分钟之前";
// else
// {
// if ( ts.Seconds > 0 ) strA = ts.Seconds.ToString() + " 秒之前";
// }
// }
// }
// }
// }
//string strB = Function.getDateTimeLaterThan(spfNews.SpfNews[i].updateTime.Ticks);
htmlstring += "<div class=\"art-post post-94269 post type-post status-publish format-standard hentry category-camera-lens tag-canon tag-ebay\">\n"
+ "<div class=\"art-post-body\">\n"
+ "<div class=\"art-post-inner art-article\">\n"
+ "<div class=\"updatetime\">发布在 " + Function.getDateTimeLaterThan(spfNews.SpfNews[i].updateTime)
+ "</div>\n"
+ "<div class=\"art-article-up\">\n"
+ "<h2 class=\"art-postheader\">"
+ (i+1).ToString() + ". " + spfNews.SpfNews[i].newsTitle + "</h2>\n"
+ "<div class=\"art-postcontent\">\n"
+ spfNews.SpfNews[i].newsContent
+ "</div>\n"
+ "</div>\n"
+ "<div class=\"cleared\"></div>\n"
+ "</div>\n"
+ "<div class=\"cleared\"></div>\n"
+ "</div>\n" + "</div>\n";
}
}
else
htmlstring += "●暂无信息\n";
this.div_post.InnerHtml = htmlstring;
}
示例8: GetUpcomingNotifications
/// <summary>
/// Get the notifications for the nex 15 minutes
/// </summary>
async Task GetUpcomingNotifications()
{
try
{
var client = new BMAStaticDataService.StaticClient();
var result = await client.GetUpcomingNotificationsAsync(DateTime.Now);
if (result.Count == 0)
return;
List<int> durationList = new List<int>();
foreach (var item in result)
{
TimeSpan ts1 = new TimeSpan(item.Time.Hour, item.Time.Minute, 0);
TimeSpan ts2 = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0);
int duration = Convert.ToInt32(Math.Round(ts1.Subtract(ts2).Duration().TotalMinutes, MidpointRounding.AwayFromZero));
durationList.Add(duration);
}
if (durationList.Count() > 0)
{
ShowNotification(durationList);
SetupTiles(durationList);
}
}
catch (Exception)
{
throw;
}
}
示例9: Main
static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
string message = "xiaopotian";
var body = Encoding.UTF8.GetBytes(message);
TimeSpan ts1 = new TimeSpan(DateTime.Now.Ticks);
for (int i = 0; i < 100000; i++)
{
channel.BasicPublish(exchange: "",
routingKey: "hello",
basicProperties: null,
body: body);
Console.WriteLine("xiaopotian");
}
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
TimeSpan ts = ts2.Subtract(ts1).Duration();
Console.WriteLine(ts.TotalMilliseconds);
}
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
示例10: Update
public void Update(TimeSpan total)
{
total = total.Subtract(Map01.start);
if (total.Ticks < 0)
total = total.Negate();
time = total.Minutes + ":" + total.Seconds.ToString("00.") + ":" + total.Milliseconds;
}
示例11: Delay
public void Delay()
{
//delay to test (3 seconds)
var delay = new TimeSpan(0, 0, 0, 3 /* seconds */);
//tollerance (actual time should be between 2.9 and 3.1 seconds)
var tollerance = new TimeSpan(0, 0, 0, 0, 100 /* milliseconds */);
Stopwatch stopwatch = new Stopwatch();
Timer timer = new Timer();
Loop.Current.QueueWork(() => {
stopwatch.Start();
timer.Start(delay, TimeSpan.Zero, () =>
{
stopwatch.Stop();
timer.Stop();
timer.Close();
});
});
Loop.Current.Run();
Assert.GreaterOrEqual(stopwatch.Elapsed, delay.Subtract(tollerance));
Assert.Less(stopwatch.Elapsed, delay.Add(tollerance));
}
示例12: GetStatusPic
public static string GetStatusPic(object Status, object TJDate, object Path)
{
if (Status.ToString() == "70")
{
if (TJDate.ToString() != "")
{
DateTime dtNow = DateTime.Now;
DateTime dtTJ = DateTime.Parse(TJDate.ToString());
//看时间,超过2天,黄灯,超过3天红灯
TimeSpan tsNow = new TimeSpan(dtNow.Ticks);
TimeSpan tsTJ = new TimeSpan(dtTJ.Ticks);
TimeSpan ts = tsNow.Subtract(tsTJ).Duration();
if (ts.Days >= 3)
{
return "<img src='"+ Path + "/Images/redLight.gif' />";
}
else if (ts.Days >= 2)
{
return "<img src='" + Path + "/Images/yellowLight.gif' />";
}
return "";
}
return "";
}
return "";
}
示例13: DateCompare
public string DateCompare(string beginDate, string endDate)
{
try
{
if (beginDate != null && endDate != null)
{
DateTime ed=Convert.ToDateTime(endDate);
DateTime bd = Convert.ToDateTime(beginDate);
//TimeSpan dt = Convert.ToDateTime(endDate) - Convert.ToDateTime(beginDate);
//return dt.ToString();
string dateDiff = null;
TimeSpan ts1 = new TimeSpan(ed.Ticks);
TimeSpan ts2 = new TimeSpan(bd.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
dateDiff =ts.Hours.ToString() + ":"
+ ts.Minutes.ToString() + ":"
+ ts.Seconds.ToString();
return dateDiff;
}
else
{
return "";
}
}
catch (Exception ex)
{
return "";
}
}
示例14: ExecDateDiff
/// <summary>
/// 程序执行时间测试
/// </summary>
/// <param name="dateBegin">开始时间</param>
/// <param name="dateEnd">结束时间</param>
/// <returns>返回(秒)单位,比如: 0.00239秒</returns>
public static string ExecDateDiff(DateTime dateBegin, DateTime dateEnd)
{
TimeSpan ts1 = new TimeSpan(dateBegin.Ticks);
TimeSpan ts2 = new TimeSpan(dateEnd.Ticks);
TimeSpan ts3 = ts1.Subtract(ts2).Duration();
return ts3.TotalMilliseconds.ToString();
}
示例15: SecondsRemainingDay
/// <summary>
/// 当天剩余秒数
/// </summary>
/// <returns></returns>
public static int SecondsRemainingDay()
{
var ts1=new TimeSpan(DateTime.Now.Ticks);
var ts2 = new TimeSpan(DateTime.Now.AddDays(1).Date.Ticks);
var ts = ts1.Subtract(ts2).Duration();
return ts.TotalSeconds.To<int>()-1;
}