I want a value from datetime picker with 24 hour format
i want this type of answer
Datetime dt=dtp.value; (here dtp means datetimepicker)
ans: dt= 27-Apr-12 16:15
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 27, 2012, 9:36 AM
A DateTime instance knows nothing about formatting itself. It's just a long integer which represents the number of ticks (1 tick = 100 nanoseconds) which have occurred from Midnight on 1 January, 0001 until the date/time in question.
When you try to convert a string to a DateTime - using DateTime.(Try)Parse or Convert.ToDateTime - certain formats will be automatically recognized and converted to the correct DateTime instance.
If this isn't working correctly for you, then you can use DateTime.(Try)ParseExact instead which attempts to parse the string to a Datetime using the format which you specify:
http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
http://msdn.microsoft.com/en-us/library/ms131044.aspx
Poppa WallacePosted Apr 27, 2012, 8:53 AM
http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm
24hrs with date
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
or this if you want AM or PM.
DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
Abdu RafeeqPosted Apr 27, 2012, 8:45 AM
but i want convert string to datetime,,,at the time this is automaticaly convert to 12 hour format
Kunal VaishyaPosted Apr 27, 2012, 8:25 AM
if Three Digit Months String
DateTime dt = DateTime.Now ;
dt.ToString("dd-MMM-yy HH:mm");
if FUll String Months String
DateTime dt = DateTime.Now ;
dt.ToString("dd-MMMM-yy HH:mm");
Kunal VaishyaPosted Apr 27, 2012, 8:25 AM
if Three Digit Months String
DateTime dt = DateTime.Now ;
dt.ToString("dd-MMM-yy HH:mm");
if FUll String Months String
DateTime dt = DateTime.Now ;
dt.ToString("dd-MMMM-yy HH:mm");
Poppa WallacePosted Apr 27, 2012, 6:23 AM
http://www.dotnetperls.com/datetime-format
VulpesPosted Apr 27, 2012, 6:08 AM
string date = dt.ToString("dd-MMM-yy HH:mm");
SenthilkumarPosted Apr 27, 2012, 6:05 AM
Try this...
You can see the other format of the date and time output in the following links.
http://www.csharp-examples.net/string-format-datetime/
http://www.dotnetperls.com/24-hour-time