locked
Time format RRS feed

  • Question

  • HI All,

    I need to format time from HH.mm.ss to HH:mm:ss.ffff i. e.

    07.49.39 to

    07:49:39.35841

    How do it do ? i tried :-

    

    DateTime time_f = DateTime.ParseExact(this.text, "HH:mm:ss", null);

    

     

    value of text is 07.49.39

    Thanks in advance

    string time = String.Format("{0:HH:mm:ss}", text

    Wednesday, July 13, 2011 10:34 AM

Answers

  • oh,

    This was only an example of using Now property of DateTime class.

    One thing: you have a string "07.49.39, where do you get last "35841" thousands from?

     

    Ok, if you have a string and you want to change it`s format you can do:

          string example = "07.49.39";
          example = example.Replace(".", ":");
          DateTime time = Convert.ToDateTime(example);
          string dateFormated = String.Format("{0:hh:mm:ss.fff}", time);
    

    But still you have a strange example.


    Mitja
    Thursday, July 14, 2011 2:29 PM

All replies

  • This does the trick:

     DateTime time = DateTime.Now;
     string dateFormated = String.Format("{0:hh:mm:ss.fff}", time);
    

    Remember: you cannot change the DateTime value to some of your format (not to any at all). You can only change the string format, based on some real date time.

     

    and btw: please change the thread to a Question. thx

     


    Mitja

    Wednesday, July 13, 2011 1:23 PM
  • Hi Mitja,

    Thanks for the reply ,But i can not use DateTime.Now. I have a string variable(in which values is put in run time) in a format 07.49.39 which should be changed to

    07:49:39.35841

    Thursday, July 14, 2011 9:27 AM
  • oh,

    This was only an example of using Now property of DateTime class.

    One thing: you have a string "07.49.39, where do you get last "35841" thousands from?

     

    Ok, if you have a string and you want to change it`s format you can do:

          string example = "07.49.39";
          example = example.Replace(".", ":");
          DateTime time = Convert.ToDateTime(example);
          string dateFormated = String.Format("{0:hh:mm:ss.fff}", time);
    

    But still you have a strange example.


    Mitja
    Thursday, July 14, 2011 2:29 PM
  • thanks Mitja,

    This will surely help

    35841 is second's fraction

    now I have one more question for you

    I have a string in the form "2011-07-13T07:38:00.000-04:00".I need to extract 07:38:00 out of it how do I do that.Need urgent reply

    Thursday, July 14, 2011 2:49 PM
  • Check for the answer here.
    Mitja
    Thursday, July 14, 2011 3:49 PM