0

I have time stored in Db as 800,1600 format in separate column. I want to add colon in time before giving it to UI. Currently I am calculating the size and zero if size is three and using insert to add colon after 2 characters.

String.Insert(2,':');

Is there any better way to do the same?

Yogesh
  • 354
  • 2
  • 15

1 Answers1

1

Use below code

string time = "800";
string s1= DateTime.ParseExact(time.PadLeft(4, '0') , "HHmm", CultureInfo.InvariantCulture).ToString("HH:mm");
Akshey Bhat
  • 8,227
  • 1
  • 20
  • 20