473,508 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with time format please

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.

Nov 10 '06 #1
3 1189
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.
"CCLeasing" <ga**@ccleasing.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
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.

Nov 10 '06 #2
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.

ChrisM wrote:
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.
"CCLeasing" <ga**@ccleasing.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
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.
Nov 10 '06 #3
double timeDiffInHours = 6; // Can be negative (eg -6) or fractional (eg
6.25)
DateTime.Now.AddHours(timeDiffInHours).ToString("h :mm tt");

Cheers,

Chris.

"CCLeasing" <ga**@ccleasing.co.ukwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
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.

ChrisM wrote:
>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.
"CCLeasing" <ga**@ccleasing.co.ukwrote in message
news:11*********************@e3g2000cwe.googlegro ups.com...
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.

Nov 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2499
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
1
4322
by: jase_dukerider | last post by:
Hi I have an assignment to hand in shortly for which I am after some guidance. The task is to read a WAV file, request a fade in /out time for the track from the user and the do the fade by...
4
2204
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
22
2145
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
6
6424
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
8
1562
by: Dhananjay | last post by:
hello everyone Do you have any information how to generate a tool using .net which is used to translate the web page contents to html format. Plz reply me asap Thanks in advance Dhananjay
2
2066
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
22
3219
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
8
2887
by: saladinator | last post by:
I have created an Excel spreadsheet that has a lot of data. What I want to do is import the spreedsheet to Access and create a form so that I can print each row per page in a proffessional manner....
4
6277
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.