String was not recognized as a valid TimeSpan

Viewed 55

I haven't any problem before, but one day (today) i have error getting whats happened ?

Error message:

System.FormatException: String was not recognized as a valid TimeSpan. at System.Globalization.TimeSpanParse.TimeSpanResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument, String failureArgumentName) at System.Globalization.TimeSpanParse.TryParseTimeSpan(String input, TimeSpanStandardStyles style, IFormatProvider formatProvider, TimeSpanResult& result) at System.Globalization.TimeSpanParse.Parse(String input, IFormatProvider formatProvider) at System.TimeSpan.Parse(String s) at www.jcp.lv.WebForm1.GetTime2(Object sender, EventArgs e) in C:\Users\edgar\Documents\Projekts JCP\software development\www.jcp.lv\webpage\www.jcp.lv\www.jcp.lv\Default.aspx.cs:line 366

Code line 366 in C#

protected void GetTime2(object sender, EventArgs e)
{
  try
  {
    CultureInfo ci = new CultureInfo("lv");
    DateTime dt = DateTime.Now;
    Label22.Text = DateTime.Now.ToString("dddd ", ci);
    Label23.Text = DateTime.Now.ToString("d.MMMM HH:mm:ss", ci);
    DayOfWeek day = DateTime.Now.DayOfWeek;
    TimeSpan CurrentTime = DateTime.Now.TimeOfDay;

    if ((day != DayOfWeek.Saturday) && (day != DayOfWeek.Sunday) && Convert.ToBoolean(ViewState["showClock"]) == true)
    {
      if ((CurrentTime >= TimeSpan.Parse(Label2.Text)) && (CurrentTime <= TimeSpan.Parse(Label3.Text)))
      {
0 Answers
Related