Help with time format please

  • Thread starter Thread starter CCLeasing
  • Start date Start date
C

CCLeasing

i'm currently using the following code without any problem.

txtTime.Text = DateTime.Now.ToString("t")

however, i want the time to be displayed with am or pm after it.

so for instance instead of 15:32, 3:32 pm

how do i do this?

Many Thanks.
 
You could do this...


DateTime.Now.ToString("hh:mm:ss tt")


The "tt" portion of the string will show the AM or PM. the "hh" is for
hours 1-12 (just use one h if you don't want to display a leading
zero), mm for minutes, ss for seconds.
 
Thanks very much that is working fine i'm using: -

txtTime.Text = DateTime.Now.ToString("h:mm tt");

One last question, I need to give the time in the control in a
different timezone to my local timezone, is there anyway i can
increment the time by a set amount of hours before i put it into the
txtTime control?

Thankyou.
 
double timeDiffInHours = 6; // Can be negative (eg -6) or fractional (eg
6.25)
DateTime.Now.AddHours(timeDiffInHours).ToString("h:mm tt");

Cheers,

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top