txbStart是一个文本框。时间以24小时格式输入为hh:mm。 lblStartUpR是一个以短时间格式显示时间的标签 txbPreStart是一个文本框相同的格式。 lblArrivalR是一个标签,用于显示短时间格式的时间,即以下计算结果为 : txbPreStart从txbStart中减去(加一个减号) ''我应该编写更简单更严格的代码来抛出异常吗? 解决方案 " Dennis D." < TE ** @ dennisys.com> schrieb VB.net似乎没有足够的结构来处理它自己代码中的时间。从00:00 AM减去15分钟,然后退出范围条件结果。从中午12点减去15分钟,结果是11:45 AM,应该如此。似乎有一半的过程丢失,而且是一半需要最多的思考。没有它,我们只需手动编码整个过程。时间有一个标准,应该用语言正确实施。时间也是编程中最常用的例程之一。虽然我可以通过编程方式解决VB时间的问题,但我认为应该解决这个问题。至少它应该与当地时间一起使用,只需要UTC转换就需要额外的代码。 为什么会这样? 您必须区分某个时间点和Timespan。 首先由Date(DateTime)值表示,第二个由Timespan (System.TimeSpan)值表示。通过查看DateTime.TimeOfDay的 数据类型,您可以在一天内的时间表示时间跨度(午夜以来的时间跨度)。 br /> 某个时间点由日期和时间组成。最小值 是DateTime.MinValue(01/01/0001 00:00)和最大的ist DateTime.MaxValue。 所以,你的错是使用DateTime变量来存储一天的时间。 当你使用 PreStartHour As Date = DateAdd( DateInterval.Hour,MinusHour, CDate(txbStart.Text)) 然后你试图从01/01/0001 00:00减去1小时。这不是 可能因为这个日期已经是 DateTime结构可能的最小值。 我不喜欢了解你的程序的目的,但我建议使用DateTime和TimeSpan结构的 成员从/转换为 String / DateTime / Timespan,如 - DateTime.Parse,DateTime.ParseExact - DateTime.Add,DateTime.Subtract - DateTime和TimeSpan的构造函数 - TimeSpan.Add 和所有其他成员。 也许你可以描述一下程序的目的,我可以告诉你如何 我会实现它。 - Armin 如何引用及其原因: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/new s / learn2quote.html " Armin Zingler" < AZ ******* @ freenet.de>在消息中写道 news:40 *********************** @ news.freenet.de ... Dennis D. < TE ** @ dennisys.com> schrieb VB.net似乎没有足够的结构来处理它自己代码中的时间。从00:00 AM减去15分钟,然后退出范围条件结果。从中午12点减去15分钟,结果是11:45 AM,应该如此。似乎有一半的过程丢失,而且是一半需要最多的思考。没有它,我们只需手动编码整个过程。时间有一个标准,应该用语言正确实施。时间也是编程中最常用的例程之一。虽然我可以通过编程方式解决VB时间的问题,但我认为应该解决这个问题。至少它应该与当地时间一起工作,只需要UTC转换需要额外的代码。 为什么它是这样的?你必须区分某个时间点和时间跨度。 首先由Date(DateTime)值表示,第二个由Timespan (System.TimeSpan)值表示。通过查看DateTime.TimeOfDay的数据类型,您可以在一天内的时间表示时间跨度(午夜以来的时间跨度)。 A某个时间点由日期和时间组成。最小的 值是DateTime.MinValue(01/01/0001 00:00)和最大的ist DateTime.MaxValue。 所以,你的错是使用DateTime变量来存储当天的时间。当你使用 PreStartHour As Date = DateAdd(DateInterval.Hour,MinusHour, CDate( txbStart.Text)) 然后你试图从01/01/0001 00:00减去1小时。这不可能,因为这个日期已经是 DateTime结构可能的最小值。 我不明白你的程序的目的,但我建议使用DateTime和TimeSpan结构的成员转换/到 String / DateTime / Timespan,如 - DateTime.Parse,DateTime.ParseExact - DateTime.Add, DateTime.Subtract - DateTime和TimeSpan的构造者 - TimeSpan.Add 和所有其他成员。 也许您可以描述程序的目的和我可以告诉你我将如何实现它。 - Armin 如何报价和原因: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html 这是我的观点t $。 假定日期,或者你必须给节目一个日期 (2001年1月1日)。 但是什么时候是不是00:00减00:15而不是23:45 24小时制?它始终是23:45! 那么为什么要通过所有这些代码来得出一个简单的事实呢? 最坏的情况下应该需要2行代码来说: 00:00 - 00:15 == 23:45 因为此时没有人承担任何责任。 没有人说过Daylight储蓄,或过去的Prime Meridian。 如果我想指定一些额外的东西,比如DST或UTC, 那么我就能理解被要求的难度/> 提供更多信息。 但是时间类型应该有一些简单的谦逊 假设,如果你超越了负边界那么 从父母那里减去一个单位,无论是什么。 0 - 1 = -1,这有多难? 时间:00:00- 00:15 = 23:45,或者 00:00 - 01:01 = 23:59,对我来说似乎很简单。 这不是怎么回事工作? 我知道。 这就是我推荐行动的原因。 高级语言应该对此没有问题。 oops:00:00-01:01:22:22 我想。脑屁! " Dennis D." < TE ** @ dennisys.com>在消息中写道 新闻:eY ************** @ TK2MSFTNGP12.phx.gbl ... " ; Armin Zingler < AZ ******* @ freenet.de>在消息中写道新闻:40 *********************** @ news.freenet.de ... Dennis D. < TE ** @ dennisys.com> schrieb VB.net似乎没有足够的结构来处理它自己代码中的时间。从00:00 AM减去15分钟,然后退出范围条件结果。从中午12点减去15分钟,结果是11:45 AM,应该如此。似乎有一半的过程丢失,而且是一半需要最多的思考。没有它,我们只需手动编码整个过程。时间有一个标准,应该用语言正确实施。时间也是编程中最常用的例程之一。虽然我可以通过编程方式解决VB时间的问题,但我认为应该解决这个问题。至少它应该与当地时间一起使用,只需要UTC转换就需要额外的代码。 为什么会这样? 你必须区分某个时间点和Timespan。 首先由Date(DateTime)值表示,第二个由 Timespan(System.TimeSpan)值表示。一天内的时间也用时间跨度(午夜以来的时间跨度)表示,你可以通过查看 DateTime.TimeOfDay的数据类型来看。 A某个时间点由日期和时间组成。最小的 值是DateTime.MinValue(01/01/0001 00:00)和最大的ist DateTime.MaxValue。 所以,你的错是使用DateTime变量来存储天的时间。当你使用 PreStartHour As Date = DateAdd(DateInterval.Hour,MinusHour, CDate(txbStart.Text)) 然后你试图减去1小时从01/01/0001 00:00。这是不可能,因为这个日期已经是 DateTime结构可能的最小值。 我不明白你的程序的目的,但我建议使用将DateTime和TimeSpan结构的成员转换为/到 String / DateTime / Timespan,如 - DateTime.Parse,DateTime.ParseExact - DateTime.Add, DateTime.Subtract - DateTime和TimeSpan的构造者 - TimeSpan.Add 和所有其他成员。 也许您可以描述程序的目的和我可以告诉你 如何我会实现它。 - Armin 如何引用以及为什么: http://www.plig.net/nnq/nquote。 html http://www.netmeister.org /news/learn2quote.html 这就是我的观点。假设一个日期,或者你必须给节目一个日期(2001年1月1日)。但是什么时候不是00:00减去00:15而不是23:45的24小时时钟?它始终是23:45!那么为什么要通过所有这些代码来得出一个简单的事实?最坏的情况下应该需要2行代码来说: 00:00 - 00 :15 == 23:45 因为在这一点上没有人有任何假设。没有人说过夏令时,或者过了Prime Meridian。如果我想特别指出一些东西,比如DST或UTC,然后我就能理解被要求提供更多信息的难度。但是时间类型应该有一些简单的不张扬的假设,如果你越过负面边界它将从父母那里减去一个单位,无论是什么。 0 - 1 = -1,这有多难?时间:00:00 - 00: 15 = 23:45,或者说00:00 - 01:01 = 23:59,对我来说似乎很简单。这不是它的工作原理吗?我知道。高级语言不应该有这个问题。 VB.net does not seem to have adequate structure for handling timewithin it''s own code.Subtract 15 minutes from 00:00 AM, and an out of range condition results.Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM,as it should be.Seems one half of the process is missing, and it is the half that requiresthe most thought. Without it, we are left to hand code the whole process.Time has a standard, and it should be properly implemented in the language.Time is also one of the most commonly used routines in programming.While I could work around the VB time construct programmatically, I feelthat the issue should be addressed. At least it should work with local time,with only UTC conversion requiring additional code.Why is it the way it is?Here''s the code:Private Sub btnAction_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnAction.Click''begin StartTextDim StartText As String = txbStart.TextDim HourParse As String = Mid(StartText, 1, 2)Dim HourDbl As Double = Val(HourParse)Dim HourInt As Integer = CInt(HourDbl)Dim MinParse As String = Mid(StartText, 4, 2)Dim MinDbl As Double = Val(MinParse)Dim MinInt As Integer = CInt(MinDbl)Dim SecInt As Integer = 0Dim FunctionTime As Date = TimeSerial(HourInt, MinInt, SecInt)Dim StartLabelText As String = Format(FunctionTime, "hh:mm tt")''Set Start Time LabellblStartUpR.Text = StartLabelText''end StartText''begin PreStartDim PreStart As String = txbPreStart.TextHourParse = Mid(PreStart, 1, 2)HourDbl = Val(HourParse)HourInt = CInt(HourDbl)MinParse = Mid(PreStart, 4, 2)MinDbl = Val(MinParse)MinInt = CInt(MinDbl)''Begin CalcDim MinusHour As Double = HourDbl * -1Dim MinusMin As Double = MinDbl * -1Dim PreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour,CDate(txbStart.Text))Dim PreStartHourDbl As Double = Val(PreStartHour)Dim PreStartHourInt As Integer = CInt(PreStartHourDbl)Dim PreStartMin As Date = DateAdd(DateInterval.Minute, MinusMin,CDate(txbStart.Text))Dim PreStartMinDbl As Double = Val(PreStartMin)Dim PreStartInt As Integer = CInt(PreStartMinDbl)FunctionTime = TimeSerial(HourInt, MinInt, SecInt)StartLabelText = Format(FunctionTime, "hh:mm tt")lblArrivalR.Text = PreStartMin.ToShortTimeStringEnd SubtxbStart is a textbox. The time is entered in 24hour format as hh:mm.lblStartUpR is a label that displays the time in short time formattxbPreStart is a textbox taking the same format.lblArrivalR is a label that displays the time in short time format that is aresult of the following calculation:txbPreStart is subtracted (by addition of a minus value) from txbStart''Should I write simpler and tighter code to throw the exception? 解决方案 "Dennis D." <te**@dennisys.com> schrieb VB.net does not seem to have adequate structure for handling time within it''s own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmatically, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code. Why is it the way it is?You must distinguish between a certain point in time and a Timespan. Thefirst is expressed by a Date (DateTime) value and the second by a Timespan(System.TimeSpan) value. The time within a day is also expressed by aTimespan (the timespan since midnight) as you see by having a look at thedata type of DateTime.TimeOfDay.A certain point in time is composed of a date and a time. The smallest valueis DateTime.MinValue (01/01/0001 00:00) and the largest istDateTime.MaxValue.So, your fault is to use a DateTime variable to store the time of the day.When you usePreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour,CDate(txbStart.Text))then you are trying to subtract 1 hour from 01/01/0001 00:00. This is notpossible because this date is already the smallest value possible for aDateTime structure.I don''t understand the purpose of your procedure, but I suggest to use themembers of the DateTime and TimeSpan structures to convert from/toString/DateTime/Timespan, like- DateTime.Parse, DateTime.ParseExact- DateTime.Add, DateTime.Subtract- Constructors for DateTime and TimeSpan- TimeSpan.Addand all the other members.Maybe you could describe the purpose of the procedure and I can show you howI would implement it.--ArminHow to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html"Armin Zingler" <az*******@freenet.de> wrote in messagenews:40***********************@news.freenet.de... "Dennis D." <te**@dennisys.com> schrieb VB.net does not seem to have adequate structure for handling time within it''s own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmatically, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code. Why is it the way it is? You must distinguish between a certain point in time and a Timespan. The first is expressed by a Date (DateTime) value and the second by a Timespan (System.TimeSpan) value. The time within a day is also expressed by a Timespan (the timespan since midnight) as you see by having a look at the data type of DateTime.TimeOfDay. A certain point in time is composed of a date and a time. The smallestvalue is DateTime.MinValue (01/01/0001 00:00) and the largest ist DateTime.MaxValue. So, your fault is to use a DateTime variable to store the time of the day. When you use PreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour, CDate(txbStart.Text)) then you are trying to subtract 1 hour from 01/01/0001 00:00. This is not possible because this date is already the smallest value possible for a DateTime structure. I don''t understand the purpose of your procedure, but I suggest to use the members of the DateTime and TimeSpan structures to convert from/to String/DateTime/Timespan, like - DateTime.Parse, DateTime.ParseExact - DateTime.Add, DateTime.Subtract - Constructors for DateTime and TimeSpan - TimeSpan.Add and all the other members. Maybe you could describe the purpose of the procedure and I can show youhow I would implement it. -- Armin How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.htmlThat''s my point exactly.A date is assumed, or you must give the program a date(as January 01, 2001).But when is not 00:00 minus 00:15 not 23:45 on a24 hour clock? It is always 23:45!So why go through all this code to arrive at a simple fact?It should require 2 lines of code at worst to say:00:00 - 00:15 == 23:45Because at this point no one has assumed anything.No one has said Daylight savings, or past the Prime Meridian.If I wanted to specifiy something extra, such as DST or UTC,then I could understand the difficulty of being required toprovide more information.But a time type should have some simple unassumingassumptions, that if you move past the negative boundry itsubtracts one unit from the parent, whatever that is.0 - 1 = -1, how difficult is that?In time: 00:00 - 00:15 = 23:45, or00:00 - 01:01 = 23:59, seems simple enough to me.That''s not how it works?I know.That is why I am recommending action.A high level language shouldn''t have a problem with this.oops: 00:00 - 01:01 = 22:59I think. Brain Fart!"Dennis D." <te**@dennisys.com> wrote in messagenews:eY**************@TK2MSFTNGP12.phx.gbl... "Armin Zingler" <az*******@freenet.de> wrote in message news:40***********************@news.freenet.de... "Dennis D." <te**@dennisys.com> schrieb VB.net does not seem to have adequate structure for handling time within it''s own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM, and the result is 11:45 AM, as it should be. Seems one half of the process is missing, and it is the half that requires the most thought. Without it, we are left to hand code the whole process. Time has a standard, and it should be properly implemented in the language. Time is also one of the most commonly used routines in programming. While I could work around the VB time construct programmatically, I feel that the issue should be addressed. At least it should work with local time, with only UTC conversion requiring additional code. Why is it the way it is? You must distinguish between a certain point in time and a Timespan. The first is expressed by a Date (DateTime) value and the second by aTimespan (System.TimeSpan) value. The time within a day is also expressed by a Timespan (the timespan since midnight) as you see by having a look atthe data type of DateTime.TimeOfDay. A certain point in time is composed of a date and a time. The smallest value is DateTime.MinValue (01/01/0001 00:00) and the largest ist DateTime.MaxValue. So, your fault is to use a DateTime variable to store the time of theday. When you use PreStartHour As Date = DateAdd(DateInterval.Hour, MinusHour, CDate(txbStart.Text)) then you are trying to subtract 1 hour from 01/01/0001 00:00. This isnot possible because this date is already the smallest value possible for a DateTime structure. I don''t understand the purpose of your procedure, but I suggest to usethe members of the DateTime and TimeSpan structures to convert from/to String/DateTime/Timespan, like - DateTime.Parse, DateTime.ParseExact - DateTime.Add, DateTime.Subtract - Constructors for DateTime and TimeSpan - TimeSpan.Add and all the other members. Maybe you could describe the purpose of the procedure and I can show you how I would implement it. -- Armin How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html That''s my point exactly. A date is assumed, or you must give the program a date (as January 01, 2001). But when is not 00:00 minus 00:15 not 23:45 on a 24 hour clock? It is always 23:45! So why go through all this code to arrive at a simple fact? It should require 2 lines of code at worst to say: 00:00 - 00:15 == 23:45 Because at this point no one has assumed anything. No one has said Daylight savings, or past the Prime Meridian. If I wanted to specifiy something extra, such as DST or UTC, then I could understand the difficulty of being required to provide more information. But a time type should have some simple unassuming assumptions, that if you move past the negative boundry it subtracts one unit from the parent, whatever that is. 0 - 1 = -1, how difficult is that? In time: 00:00 - 00:15 = 23:45, or 00:00 - 01:01 = 23:59, seems simple enough to me. That''s not how it works? I know. That is why I am recommending action. A high level language shouldn''t have a problem with this. 这篇关于午夜前10分钟超出范围。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 07:46