TimeSpan
aから aに変換するには、string
を活用できますが、次のTimeSpan.Parse
形式に準拠する必要があります[ws][-]{ d | [d.]hh:mm[:ss[.ff]] }[ws]
。
ws is Optional white space.
- is An optional minus sign, which indicates a negative TimeSpan.
d is Days, ranging from 0 to 10675199.
. is A culture-sensitive symbol that separates days from hours. The invariant format uses a period (".") character.
hh is Hours, ranging from 0 to 23.
: is The culture-sensitive time separator symbol. The invariant format uses a colon (":") character.
mm is Minutes, ranging from 0 to 59.
ss is Optional seconds, ranging from 0 to 59.
. is A culture-sensitive symbol that separates seconds from fractions of a second. The invariant format uses a period (".") character.
ff is Optional fractional seconds, consisting of one to seven decimal digits.
したがって、実際には使用TimeSpan.Parse
して文字列を渡すだけで日を変換できますが、分を変換する場合は、次のように入力を処理する必要があります。
var input = string.Format("00:{0}", objTextBox.Text.PadLeft(2, '0'));
var timeSpan = TimeSpan.Parse(input);
適切にフォーマットされているため、発行でき、Parse
成功します。別のオプションは、私が推測する分を日に変えることですが、それには浮動小数点の作業が必要であり、実際には、IMO ほど良いオプションではありません。