Tag: 时间

C#如何用时间步实现循环

我需要实现一个包含应该每个运行的指令循环的函数.01秒有没有办法实现一个循环(例如每个时间步),可以提前做到这一点

在C#中表示时间(不是日期和时间)

我正在开发一款需要开放时间概念的应用程序(有点像商店) 如何最好地代表这些? 它们将在以后持久存储在数据库中…… 到目前为止,我有以下课程: public class OpeningTime { public DayOfWeek DayOfWeek { get; set; } public DateTime OpeningTime { get; set; } public DateTime ClosingTime { get; set; } } 所以我虚构的“商店”课程会是这样的: public class Shop { public string Name { get; set; } public string Address { get; set; } public List OpeningTimes { get; set; […]

是否在dotNet(或C#)中考虑了leapseconds?

DateTime结构是否解决了这个问题? 有没有其他类/结构? 更新: 我现在已经知道,只有提前6个月宣布跳跃,因为地球的旋转不是那么可预测的…… 既然在将来的日期里没有可能实现它,我可以想象他们只是省略了它们?

如何validation“日期和时间”字符串是否只有时间?

我有一个字符串变量存储可能是完整日期或部分日期: 1)完整日期:12/12/2010 12:33 AM 2)部分日期:上午12:33(仅限日期字段) 我试图找出解析字符串的最佳方法,以确定字符串是否缺少日期字符串。 原因是,在我的代码中如果缺少日期,我将在字符串中附加一个默认日期(例如1/1/1900)。 请记住,时间可能是各种格式。 更新 – 我对这个问题的具体答案。 正如所有“post”所述,这个问题有多个答案,这最终是我用过的,希望它可以帮助其他人*: public DateTime ProcessDateAndTime(string dateString) { string dateAndTimeString = dateString; string[] timeFormats = new string[] { “hh:mm tt”, “hh:mm:ss tt”, “h:mm tt”, “h:mm:ss tt”, “HH:mm:ss”, “HH:mm”, “H:mm” }; // check to see if the date string has a time only DateTime dateTimeTemp; if (DateTime.TryParseExact(dateString, […]

在C#中将时间转换为十进制

我需要做的是,有两个由用户输入的定义字符串, string in = “9:35”; //am string out = “11:55”; //am 我需要减去它们,以便获得它们签署的总小时数。这应该等于: string total = “2:20” 然后,我需要将其转换为十进制..所以,2:20将是 string decimal = “2.33”; 我不知道该怎么做,任何帮助将不胜感激! PS:id也喜欢能够从十进制数中计算出他们检查的总小时数,所以基本上相反

如何以HHMMSS格式执行c#时间validation

即使我以正确的格式传递日期,此代码的输出也将始终为false。请帮助我…这里传递的2个参数是时间和格式,即(“HHMMSS”格式)。 static bool ValidateTime(string time, string format) { try { //time = time.Replace(“:”,””); System.Globalization.DateTimeFormatInfo tinfo = new System.Globalization.DateTimeFormatInfo(); tinfo.LongTimePattern = format; DateTime dt = DateTime.ParseExact(time, “format”, tinfo); if (dt.Hour != null) { } return true; } catch (Exception e) { return false; } }

使用时间跨度比较两个时间间隔

我想在一定时间和当前时间之间进行比较,以检查它是否超过了给定的时间段。 我想我应该使用TimeSpan,但我不确定如何。 我比较的两个日期是DateTime对象。 TimeSpan ts = TimeSpan.FromSeconds(_timeInterval); if(DateTime.UtcNow.Ticks – rex.LastFired.Ticks > ts.Ticks) // bla bla

使用Noda Time的Olson时区ID到Windows标准格式

Olson和Windows时间Id之间的转换在SO上多次出现; 许多人建议Jon Skeet的Noda Time来完成这项任务。 虽然谷歌代码页面声明有一个function可以在两者之间进行转换,但我找不到有关如何执行此操作的详细信息。 谁能指出我正确的方向?

如何增加ToolTip显示时间?

我有一个GridView,在它的RowDataBound事件中,我正在分配ToolTip如下: protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (gv.HeaderRow != null && e.Row.RowType == DataControlRowType.DataRow) { e.Row.ToolTip = “Remarks: ” + ((Label)e.Row.FindControl(“lblRemarks”)).Text; } } catch (Exception ex) { BussinessLayer.RIBOException.Instance.HandleMe(this, ex); } } 在这里,我想延长ToolTip的显示时间。 这该怎么做?

将TimeSpan格式化为mm:ss表示正负TimeSpans

我正在寻找.net 3.5中的解决方案我写了以下工作解决方案: private string FormatTimeSpan(TimeSpan time) { return String.Format(“{0}{1:00}:{2:00}”, time < TimeSpan.Zero ? "-" : "", Math.Abs(time.Minutes), Math.Abs(time.Seconds)); } 但我的问题是:有更好的方法吗? 也许更短的地方,我不需要辅助function。