locked
string convert help need RRS feed

  • Question

  • Hello

                   I have following string "125415" I want to convert it to 12:54:15   

    170525   to     17:05:25

     

    How to convert it


    It's Me
    Tuesday, May 24, 2011 8:37 AM

Answers

  • TimeSpan time = DateTime.ParseExact("125415", "HHmmss", CultureInfo.InvariantCulture).TimeOfDay;
    

    Make everything as simple as possible, but not simpler.
    • Proposed as answer by Amit Govil (MCC) Tuesday, May 24, 2011 8:58 AM
    • Marked as answer by It_s Meee Tuesday, May 24, 2011 10:12 AM
    Tuesday, May 24, 2011 8:53 AM

All replies

  • You can try using Insert method of the string:

    string a = "125415";
    string b = a.Insert(2, ":");
    b = b.Insert(5, ":");
    


    Mitja

    Tuesday, May 24, 2011 8:52 AM
  • TimeSpan time = DateTime.ParseExact("125415", "HHmmss", CultureInfo.InvariantCulture).TimeOfDay;
    

    Make everything as simple as possible, but not simpler.
    • Proposed as answer by Amit Govil (MCC) Tuesday, May 24, 2011 8:58 AM
    • Marked as answer by It_s Meee Tuesday, May 24, 2011 10:12 AM
    Tuesday, May 24, 2011 8:53 AM