Help with time format please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CCLeasing

    Help with time format please

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

    txtTime.Text = DateTime.Now.To String("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.

  • ChrisM

    #2
    Re: Help with time format please

    You could do this...


    DateTime.Now.To String("hh:mm:s s 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.


    "CCLeasing" <gary@ccleasing .co.ukwrote in message
    news:1163159798 .882612.21980@e 3g2000cwe.googl egroups.com...
    i'm currently using the following code without any problem.
    >
    txtTime.Text = DateTime.Now.To String("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.
    >

    Comment

    • CCLeasing

      #3
      Re: Help with time format please

      Thanks very much that is working fine i'm using: -

      txtTime.Text = DateTime.Now.To String("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.

      ChrisM wrote:
      You could do this...
      >
      >
      DateTime.Now.To String("hh:mm:s s 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.
      >
      >
      "CCLeasing" <gary@ccleasing .co.ukwrote in message
      news:1163159798 .882612.21980@e 3g2000cwe.googl egroups.com...
      i'm currently using the following code without any problem.

      txtTime.Text = DateTime.Now.To String("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.

      Comment

      • ChrisM

        #4
        Re: Help with time format please

        double timeDiffInHours = 6; // Can be negative (eg -6) or fractional (eg
        6.25)
        DateTime.Now.Ad dHours(timeDiff InHours).ToStri ng("h:mm tt");

        Cheers,

        Chris.

        "CCLeasing" <gary@ccleasing .co.ukwrote in message
        news:1163162159 .017418.166680@ h48g2000cwc.goo glegroups.com.. .
        Thanks very much that is working fine i'm using: -
        >
        txtTime.Text = DateTime.Now.To String("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.
        >
        ChrisM wrote:
        >
        >You could do this...
        >>
        >>
        >DateTime.Now.T oString("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.
        >>
        >>
        >"CCLeasing" <gary@ccleasing .co.ukwrote in message
        >news:116315979 8.882612.21980@ e3g2000cwe.goog legroups.com...
        i'm currently using the following code without any problem.
        >
        txtTime.Text = DateTime.Now.To String("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.
        >
        >

        Comment

        Working...