Format mask for Timestamp attribute

Asked

Viewed 472 times

1

I need to display the value of the TIME attribute only HH:mm (hour and minutes). By including the following masks an error occurs:

The input character string was not in an incorrect format.

I tried it both ways:

@dia.HORAINICIO.ToString(@"hh:mm tt")
@dia.HORAINICIO.ToString("{0:t}")

My Annotation date is as follows:

[Display(Name = "Hora Inicial:")]
[DataType(DataType.Time)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:HH:mm}")]
public TimeSpan HORAINICIO { get; set; }
  • Try it like this: @dia.HORAINICIO.Tostring("hh:mm"); or @dia.HORAINICIO.Tostring("hh:mm:ss"); with seconds.

1 answer

2


Try without the tt in the mask.

string test ="08:00:00";
TimeSpan ts = TimeSpan.Parse(test);
Console.Write(ts.ToString(@"hh\:mm"));

I made a Fiddle for you, I think it will suit you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.