I want to get the exact US standard time value from my DateTime.Now string value. I tried using some different types of text formatting in C# but still unable to get the right one.
but I always get this format display 20:14:38.2283911 instead of
8:14 PM or 8:14 AM.
How do I get this type of time format like 10:15 AM, 8:45 PM, 2:35 PM and so on? Thanks.
B-) Gerry Lowry, Chief Training Architect, Paradigm Mentors Learning never ends... +1 705-999-9195 wasaga beach, ontario canada TIMTOWTDI =.there is more than one way to do it
Eh? I posted the code twice now? You are missing the tt which is AM\PM
dt.ToString("h:mm:ss tt");
you then mark someone else's post as the answer? lol
Thanks dude..You're both right. But the other guy is just more specific. You didn't explain very well at first unlike the other guy. Thanks again to both. Got it now.
Member
16 Points
143 Posts
How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 08:26 AM|timmack|LINK
I want to get the exact US standard time value from my DateTime.Now string value. I tried using some different types of text formatting in C# but still unable to get the right one.
From the codes below I tried something like this:
but I always get this format display 20:14:38.2283911 instead of 8:14 PM or 8:14 AM.
How do I get this type of time format like 10:15 AM, 8:45 PM, 2:35 PM and so on? Thanks.
All-Star
37441 Points
9076 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 08:44 AM|AidyF|LINK
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
DateNow.Now.ToString("h:mm tt")
Member
16 Points
143 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 09:17 AM|timmack|LINK
Look, that's the same link I referred to this
which will give a result of this type of format : 9/10/2014 7:10:21 PM for example,
but from this result as an example I just want to query the part of the string which is only 7:10:21 PM.
The link doesn't demonstrate how to do this method.
All-Star
37441 Points
9076 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 09:39 AM|AidyF|LINK
The code I posted does though;
DateNow.Now.ToString("h:mm:ss tt")
(forgot the "ss" bit :o ) replace DateTime.Now with whatever your date variable is
Member
16 Points
143 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 09:51 AM|timmack|LINK
Hi!
I tried something like this and it seem getting better but there's some little missing. I missed the A.M/P.M. remarks
Using the code above it will display 09:45:49 only instead of 09:45:49 a.m. What did I miss here? Thanks
Star
14297 Points
5797 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 09:53 AM|gerrylowry|LINK
@timmack
Regardless how you display a DateTime value, the DateTime Struct http://msdn.microsoft.com/en-us/library/system.datetime%28v=vs.110%29.aspx is constant.
System settings affect the display.
The safest way to get what YOU want is to concatenate the indilvidual parts.
output: 9:51:57 AM
All-Star
37441 Points
9076 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 10:19 AM|AidyF|LINK
Eh? I posted the code twice now? You are missing the tt which is AM\PM
you then mark someone else's post as the answer? lol
Member
16 Points
143 Posts
Re: How to get the exact U.S. standard time format from the DateTime.Now string value ?
Sep 10, 2014 10:29 AM|timmack|LINK
Thanks dude..You're both right. But the other guy is just more specific. You didn't explain very well at first unlike the other guy. Thanks again to both. Got it now.