Click here to Skip to main content
15,887,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need my datetime in format 2011-11-25 10:52:12.740000 ?
which format i should use ?
Posted

 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 1:37am    
Sure, a 5. (Please format 1st link.) Many answers on this page are wrong; and the knowledge of what written in the MSDN page you've referenced did not help them though :-<)
--SA
Nitesh Kejriwal 25-Nov-11 1:44am    
Link updated :)
RaviRanjanKr 25-Nov-11 1:58am    
My 5+
Nitesh Kejriwal 25-Nov-11 2:00am    
Thanks SAK & Ravi for votes :)
DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff")
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 1:35am    
Wow! So many wrong, studio or somehow inferior answers on this page! This one is not bad, my 5.
--SA
RaviRanjanKr 25-Nov-11 1:58am    
My 5+
Use this code.

Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff"));
 
Share this answer
 
v2
Comments
RaviRanjanKr 25-Nov-11 2:04am    
its better practice to Always use "pre" tag to wrap your codes.
Hi Try This..
string Date = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff");
 
Share this answer
 
C#
public static string getDate(string strDate, string strFormat)
    {
        if (clsCommon.IsDate(strDate))
        {
            if (strFormat == "")
                return String.Format("{0:yyyy-MM-dd H:mm:ss zzz}", Convert.ToDateTime(strDate));
            else
                return String.Format(strFormat, Convert.ToDateTime(strDate));
        }
        else
        {
            return strDate;
        }
    }


getDate(strdate,"");
 
Share this answer
 
v2
Comments
[no name] 25-Nov-11 1:55am    
It works as a general function. Very optimized coding.
Thanks for your help!
Hi prejval2006,
string time = String.Format(DateTime.Now.ToString(), "dd/MM/yyyy HH:mm:ss.fff");


Hope this helps :)

Regards.
 
Share this answer
 
v3
Comments
RaviRanjanKr 25-Nov-11 2:01am    
Always use "pre" tag to wrap your codes.
[no name] 25-Nov-11 2:05am    
Thanks.
You can create your own date format using string concanitation.
C#
private void Button1_Click(object sender, EventArgs e)
        {
         DateTime d = new DateTime();
         MessageBox.Show(d.Year + "-" + d.Month + "-" + d.Date + d.TimeOfDay);
        }
 
Share this answer
 
1.Just Drag the DateTimePicker

 private void frmReturnPurchase_Load(object sender, EventArgs e)
     
  { 
DtpRethurnBillDate.Format = DateTimePickerFormat.Custom;
          DtpRethurnBillDate.CustomFormat = "dd/MM/yyyy"

}
 
Share this answer
 
v2
Comments
RaviRanjanKr 25-Nov-11 2:00am    
Wrapped your code in "pre" tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900