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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Apr 27, 2012, 2:05 AM EDT
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
VulpesRank #55 · 29.2K reputationPosted Apr 27, 2012, 2:08 AM EDT
string date = dt.ToString("dd-MMM-yy HH:mm");
Poppa Wallace97 reputationPosted Apr 27, 2012, 2:23 AM EDT
http://www.dotnetperls.com/datetime-format
Kunal VaishyaRank #990 · 2K reputationPosted Apr 27, 2012, 4:25 AM EDT
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 VaishyaRank #990 · 2K reputationPosted Apr 27, 2012, 4:25 AM EDT
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");
Abdu RafeeqRank #2,262 · 623 reputationPosted Apr 27, 2012, 4:45 AM EDT
but i want convert string to datetime,,,at the time this is automaticaly convert to 12 hour format
Poppa Wallace97 reputationPosted Apr 27, 2012, 4:53 AM EDT
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")
VulpesRank #55 · 29.2K reputationPosted Apr 27, 2012, 5:36 AM EDT
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