1

I have three textboxes in my control,for hour, minute and second.

User can input the values in text boxes.

I want to return the combined value in a format like HHH:mm:ss, how can I do that ?

For example if user puts the values 4,3,45 it should be 004:03:45.

Please guide me to that, I tried with string.Format("{0:000}:{1:00}:{2:00}",ht,mt,st)

but it's not working, can I also use TimeSpan to achieve the same ?

3
  • 8
    "it's not working" does not really help anybody. What is your output? Commented Nov 17, 2010 at 10:08
  • 1
    Your code output's 004:03:45 just fine on my end. What does it output on your end? Commented Nov 17, 2010 at 10:09
  • What culture is the default one on your PC? Commented Nov 17, 2010 at 10:13

3 Answers 3

4

This guy here is always a help: http://blog.stevex.net/string-formatting-in-csharp/

I just always end up coming back to that reference :)

Sign up to request clarification or add additional context in comments.

Comments

2

My golden reference for C# String Formatting is SteveX's blog entry on the topic:

http://blog.stevex.net/string-formatting-in-csharp/

Should have the answer for you.

Comments

0

you can use string format for this purpose of string date time....... you can convert the time into string and then match it with the concatenated string from three text boxes....... i think this logic would work for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.