问题标签 [timespan]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
307 浏览

.net - System.TimeSpan 创建调试问题?(无法评估表达式,因为线程在某个点停止......)

在 C# 应用程序中使用 System.TimeSpan 和 WPF。TimeSpan 是方法调用中的参数。

使用 VS 2009,在尝试查看 timeCount 的值时,调试器中会显示此错误:

无法评估表达式,因为线程在无法进行垃圾收集的点停止

问题是一旦出现此错误,对象的属性值就无法调试(不限于 TimeSpan 实例),会显示相同的消息。

MS 报告无法安全调试大型结构,并且调试器会显示此消息。有什么比将结构包装在一个类中更优雅的解决方法吗?


我正在使用 VS Express 2008,按下 F5 时会自动选择调试设置,我没有太多选项可供选择。

0 投票
1 回答
441 浏览

c# - 延迟超时解决断路器正在抛出 ArgumentOutOfRangeException

Ayende 发布了对 Davy Brion断路器的修改,其中他将超时分辨率更改为惰性模型。

但是,构造函数可能会失败,因为 aTimeSpan可以快速溢出 a 的最大值DateTime。例如,当断路器的超时是 TimeSpan 的最大值时。

System.ArgumentOutOfRangeException 被捕获

Message="添加或减去的值导致无法表示的日期时间。"

...

在 System.DateTime.op_Addition(DateTime d, TimeSpan t)

我们如何避免这个问题并保持预期的行为?

0 投票
1 回答
5623 浏览

vb.net - 使用 String.Format 自定义格式时间跨度

我想将时间跨度格式化为这样的格式 49 hr 34 mn 20 sec

我使用了下面的字符串格式:

它将时间跨度格式化为这种格式 49:34:20。如何将 hr mn sec 添加到上面的 String.Format 中?还是有另一种简单的方法?谢谢你。

0 投票
8 回答
56151 浏览

c# - C# 4.0: Can I use a TimeSpan as an optional parameter with a default value?

Both of these generate an error saying they must be a compile-time constant:

First of all, can someone explain why these values can't be determined at compile time? And is there a way to specify a default value for an optional TimeSpan object?

0 投票
2 回答
1317 浏览

c# - Incorrect format timespan

I am currently tryibng to convert a given time(Entered via a text box) , The time entered would look a little like 01 52 22 mins secs mili secs.

however Timespan.parse(tbName.text) gives me an incorrect format error.

I have got it to work if i input something like 46 in to the textbox but then it sets the days to 46 not the seconds.

Any ideas how to get it just to set the mins seconds and mili seconds from the text input stated above?

I am pretty sure timespan is the way to go but many posts i have read use the dateTime and only use the time part of the variable via formatting

0 投票
7 回答
38386 浏览

sql-server-2005 - 将 .NET 刻度转换为 SQL Server 日期时间

TimeSpan在我的数据库中保存一个(来自.NET)值,就像BIGINT在 SQL Server 中一样(保存 Ticks 属性)。我想知道如何将此BIGINT值转换为DATETIMESQL Server(而不是 .NET)中的值。有任何想法吗?

干杯

编辑:

我正在使用 NHibernate 来映射TimeSpan我拥有的属性,并且它保留了 Ticks 属性。我用它来控制某个日期的相对小时(或分钟)。

在系统内部,一切都很好,不需要这种转换。但是,在 SQL Server 中执行随机查询时,很难理解TimeSpan. 因此,我传递Ticks值并DateTime返回 a 的函数将以小时、分钟和秒为单位给出它所TimeSpan代表的数量。

0 投票
5 回答
2452 浏览

c# - 在 C# 中计算过去的日期时间

我正在研究 C# 中的一种算法,以根据具有以下特征的输入字符串计算过去的 DateTime:

该字符串包含一个整数,后跟“D”、“M”或“Y”,例如“1D”或“90M”。

输出将为 DateTime.Now 减去相应的天数、月数或年数。

我遇到的问题是,例如,如果我在正则表达式(D、M 或 Y)上切换输入字符串并从 DateTime.Now 中减去相应的 TimeSpan,则新的 TimeSpan() 构造函数不接受月或年,只有几天。

如果输入字符串以天为单位,则此逻辑很好,但 TimeSpan 的构造函数不接受月或年,如果我假设每个月有 30 天,或者每年有 365 天,那将是非常不准确的。

有人对如何实现这个算法有想法吗?

谢谢!

0 投票
8 回答
10096 浏览

c# - 如何实现时间跨度到字符串的转换?

我尝试在这里搜索,但对我没有多大帮助..
我想time_span 转换为字符串,我不想以天为单位返回时间跨度..但只有 HH:mm:ss。如何做到这一点?

我的示例代码在这里:

0 投票
1 回答
3342 浏览

function - 用于将秒转换为时间跨度格式的水晶报表功能

我有一个水晶报告,它用饼图显示代理全天的活动。在详细信息部分中,它显示:

  • 活动 [字符串]
  • 开始于 [日期时间]
  • 结束于 [日期时间]
  • 持续时间 [EndedAt 和 StartedAt 之间的差异,以秒为单位 - 整数]

报告数据按活动分组并按持续时间汇总。

目前持续时间以秒为单位显示,但我需要将其格式化为 02h:30m:22s:15ms。为此,我在公式工作室编辑器中的 Crystal Report 中编写了一个自定义函数,如下所示,但看起来语法不正确(关键字 Long 上的错误消息:“缺少变量类型(例如,'String')。” )。有人可以帮忙吗?

0 投票
3 回答
1545 浏览

c# - TimeSpan 到 C# 中的本地化字符串

有没有一种简单的方法(可能是内置的解决方案)来转换TimeSpan为本地化字符串?例如new TimeSpan(3, 5, 0);将转换为3 hours, 5minutes(仅用波兰语)。

我当然可以创建自己的扩展:

但是,如果我想涉及正确的语法,这会变得复杂。